470,571 Members | 2,394 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,571 developers. It's quick & easy.

Using a Do Until Loop to search for and modify data in a table

Here is my code:
Expand|Select|Wrap|Line Numbers
  1.     Dim db As DAO.Database
  2.     Dim rs1 As DAO.Recordset
  4.     Set db = CurrentDb()
  5.     Set rs1 = db.OpenRecordset("CartUse")
  6.     rs1.MoveFirst
  8.     Do Until rs1.EOF
  9.         If rs1.Fields(ID) = Val(ID) Then
  10.             NumOrdTotal = Val(rs1.Fields(varLongMonth)) + Val(varNumOrd)
  11.             txttest2 = Val(NumOrdTotal)
  12.             rs1.Edit
  13.             rs1.Fields(varLongMonth) = Val(NumOrdTotal)
  14.             rs1.Update
  15.         End If
  16.         rs1.MoveNext
  17.     Loop
  19.   rs1.Close
  20.   Set rs1 = Nothing
  21.   Set db = Nothing
What I am needing this to do is search through my table to match the value of the Field "ID" to the value of (ID), which is a txtBox on a form bound to another table. If it matches these two values then I need it to do the calculations in the If statement. It works for the first record, but will not work for any of the other records. Both ID fields are autonumber fields.
Feb 16 '07 #1
3 1805
3,080 Expert 2GB
Not sure why you want this, as normally this is done by using a query.
The problem with your code is the fact that you need to use:
If rs1.Fields("ID") = Val(Me.ID) Then
The " is needed to refer to the field value in the recordset, alternatively you could use:
If rs1!ID = Val(Me.ID) Then
When referring to form fields it's better to use the Me infront of the name.

Feb 16 '07 #2
Thanks Nico that is all I needed.
Feb 16 '07 #3
3,080 Expert 2GB
Glad I could help, success with the application !

Feb 16 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Japhy | last post: by
3 posts views Thread by Random Person | last post: by
1 post views Thread by Daveyk0 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.