By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,662 Members | 1,790 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,662 IT Pros & Developers. It's quick & easy.

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

P: 49
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
Share this Question
Share on Google+
3 Replies


nico5038
Expert 2.5K+
P: 3,072
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

P: 49
Thanks Nico that is all I needed.
Feb 16 '07 #3

nico5038
Expert 2.5K+
P: 3,072
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.