Problem with Do While and .Move Next

S

Steve_G

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.Update
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
 
A

Alex Dybenko

Hi,
not sure I understand your code, for example "If [Post-CEP] = [Post-CEP]
Then" - will always be true, as you compare variable (or control value?)
with itself. or there is some typo?
now you loop will run until rst.EOF will be true
 
S

Steve_G

Yes, it its not very understandable.

Acctually I have a field Post-CEP in the database and I have a form which has
a field POst-CEP. The form inserts new records in the database. If the user
input already exist in the database then the form increments the number by 1
 
A

Alex Dybenko

then should be something like this:

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

but still not clear why do you run rst.Update, if you do not update
recordset
 
Top