473,505 Members | 13,696 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access VBA DAO recordset loop using two recordsets

MMcCarthy
14,534 Recognized Expert Moderator MVP
The following code is simply an example of some code that processes through two recordsets. It can be helpful for anyone curious as to how to start processing with recordsets (Which objects to refer to & how to set them up correctly etc), as well as for those who want a quick run-through of some basic multi-recordset logic.
Expand|Select|Wrap|Line Numbers
  1. Function yourFunctionName() 
  2. Dim db As DAO.Database
  3. Dim rs1 As DAO.Recordset
  4. Dim rs2 As DAO.Recordset
  5.  
  6.   Set db = CurrentDb() 
  7.   Set rs1 = db.OpenRecordset("Query1") 
  8.   Set rs2 = db.OpenRecordset("Query2")
  9.  
  10.   If rs1.RecordCount=0 Then Exit Sub
  11.  
  12.   rs1.MoveFirst 
  13.   ' loop through each record in the first recordset
  14.   Do Until rs1.EOF
  15.     ' If matching record is found then update field in 
  16.     ' second recordset to value you determine
  17.    If rs2.RecordCount=0 Then Exit Sub
  18.     rs2.MoveFirst
  19.     Do Until rs2.EOF
  20.       If rs1![FieldName] = rs2!FieldName Then
  21.         rs2.Edit
  22.         rs2![FieldName] = 'Your Value'
  23.         rs2.Update
  24.       End If
  25.       rs2.MoveNext
  26.     Loop
  27.     rs1.MoveNext
  28.   Loop
  29.  
  30.   rs1.Close 
  31.   rs2.Close 
  32.   Set rs1 = Nothing
  33.   Set rs2 = Nothing
  34.   Set db = Nothing
  35.  
  36. End Function
Remember this is just an example and not by any means the only way of achieving this.
Jan 1 '07 #1
4 68635
william.purcell
1 New Member
This was a clear, concise example for a novice like me. Thanks for the effort. I sure wish I had seen this on Friday.
Bill
Feb 24 '08 #2
Sunshard
15 New Member
This was really helpful, so thank you for posting.

Brian
Feb 26 '08 #3
ahmedtharwat19
55 New Member
perfect code

i use it in my project

thank you

ahmed tharwat
Jun 6 '10 #4
This the best example source code for me. I am going to use it in my project. I am sure, after making some changes I will get the result I want. Thanks a lot
Oct 1 '10 #5

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

Similar topics

13
15081
by: Sateesh | last post by:
Hi, Is it possible to access Lotus notes using Python? Can anyone provide me some pointers? Thanks Sateesh
2
7193
by: jd | last post by:
Hi, I have an xsl as below. I am trying to loop using <xsl:for-each> and in the select attribute of <xsl:for-each> i am getting the nodeset from the external javascript function in the <CDATA>...
3
1760
by: stueyh | last post by:
When attempting to connect to an Access 2000 DB using ADO.Net from within ASP.Net running under an impersonated local user account receiving the following error. ERROR Disk or network error....
1
2667
by: Andy | last post by:
Hi, I was wondering if someone could advise on if the following is possible. I have one website that is available to the public using Forms authentication and the Membership class, it...
2
4539
by: pratcp | last post by:
I have a remote server (a shared hosting webserver) where I have few users ftp some flat files. I need to access these files using a windows app/windows service written using c# and run it on a...
3
5210
by: Suresh P | last post by:
Hi All, I tried to access the mysql database in ODBC using ip address and username/password. It returns, "cannot connect to MySQL server on IP ADDRESS(10060)". This could be related to Firewall...
8
3529
by: Bhuwan Bhaskar | last post by:
Hi, Can we access database (SQL) using AJAX ? Thanks, Bhuwan
1
3635
by: BharathP | last post by:
Hi, I need to transfer data of one of the table in DB2 to Microsoft Access. I tried using DBOP data source using Configuration assistant in DB2 and SQL passthrough in Microsoft Access. I think I'm...
1
1645
by: BharathP | last post by:
Hi, I need to transfer data of one of the table in DB2 to Microsoft Access. I tried using DBOP data source using Configuration assistant in DB2 and SQL passthrough in Microsoft Access. I think I'm...
0
7213
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7298
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4698
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1526
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.