468,170 Members | 2,006 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,170 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
  3.  
  4.     Set db = CurrentDb()
  5.     Set rs1 = db.OpenRecordset("CartUse")
  6.     rs1.MoveFirst
  7.  
  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
  18.  
  19.   rs1.Close
  20.   Set rs1 = Nothing
  21.   Set db = Nothing
  22.  
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 1729
nico5038
3,079 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.

Nic;o)
Feb 16 '07 #2
Thanks Nico that is all I needed.
Feb 16 '07 #3
nico5038
3,079 Expert 2GB
Glad I could help, success with the application !

Nic;o)
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
1 post views Thread by gcdp | last post: by
reply views Thread by kamranasdasdas | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.