Problem with Do While and .Move Next

  • Thread starter Thread starter Steve_G
  • Start date Start date
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
 
Acctually, there is no

rst.Update

in the code, I receive error message
 
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
 
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
 
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
 
I am not. See my second post right after the initial. I'll test your input
now
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top