473,379 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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 2009
nico5038
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.

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

Nic;o)
Feb 16 '07 #4

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

Similar topics

4
by: Japhy | last post by:
Hello, I'm am pulling data from a mysql db and want to use the data to populate a <ul. Here are relavent parts of my code : $wohdate = mysql_result($wohRS,$wohndx,woh_date); $woh_display...
3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
8
by: doomx | last post by:
I'm using SQL scripts to create and alter tables in my DB I want to know if it's possible to fill the description(like in the Create table UI) using these scripts. EX: CREATE TABLE(...
1
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
6
by: ransoma22 | last post by:
I developing an application that receive SMS from a connected GSM handphone, e.g Siemens M55, Nokia 6230,etc through the data cable. The application(VB.NET) will receive the SMS automatically,...
16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
1
by: Jason Northampton | last post by:
Hello This is the first time I've used a discusion forum and up until now I have managed to use and or modify VB code from the various sites on the web, until now! This is a simple problem and I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.