Problem with Do While and .Move Next

Steve_G

New member
Joined
Jan 23, 2006
Messages
2
Programming Experience
1-3
Hi, I have the following code

Do While Not rst.EOF
If [Post-CEP] = [Post-CEP] Then
[Post-CEP] = [Post-CEP] + 1
intCount = intCount + 1
rst.MoveNext
Else
Exit Do
End If
Loop

There are already value for Post-CEP to be 001. When I execute the code it
goes and adds another record by incrementing Post-CEP by 1 so the new value
is 002. Now every time when the code is executed is should Loop through the
records and increment by 1 when the last record is accessed. Unfortunately,
it stops right after the 002 and then each new record is assigned 002. How
can I fix that?

Thanks
 
Steve,

I am not very experienced in Visual Basic but I have never seen the use of objects between brackets. I have tried your code and the IDE keeps warning:" Bracketed identifier is missing closing ']'.

Anyway, your test
VB.NET:
[SIZE=2][COLOR=#0000ff]
If[/COLOR][/SIZE][SIZE=2] [Post-CEP] = [Post-CEP]
[/SIZE]
will always be true, it's like testing
VB.NET:
If 1=1
Therefore your 'Exit Do' is useless.
 
yes,

I didn't clarify the post. The second [Post-Cpe] is a field in a database table. the first [post-CPE] is a field in a form which inserts the record. So, if the user enters something the code checks against the database if the number already exist. I user the Loop to loop through all records. In case the number already exists then the code should incrment by 1.
 
Instead of this method u can simply find out the Maximum number from the list n increment it by one and then assign it to the post value which u want to insert. U can find the maximum value by usin the followin 2 techniques:

1) "Select max(post) from Table"

2) Use the Bubble Sort/Selection Sort to find the maximum number of the given series.
 
Back
Top