Wrox Programmer Forums
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 14th, 2005, 08:25 PM
Authorized User
Join Date: Apr 2004
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default Filter recordset in loop


I have 2 recordsets rs1=ADO recordset and rs2=DAO recordset.
I need to filter rs2 inside a loop as rs1 changes value for each loop and I need to find the same value in rs2.
Anyone know how to acheive this?

Cheers / Fred

Old February 15th, 2005, 09:09 AM
Friend of Wrox
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts


Here is how I did a similar thing with two recordsets, one in Access, and one in SQL. Basically you open both recordsets and then manage your loops.

On Error Resume Next
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3

strDate = Date
strTime = Time

strUserName = "SQLUserName"
strPassword = "SQLPassword"

'Access DSN
Set objConn = CreateObject("ADODB.Connection")
Set objRS = CreateObject("ADODB.Recordset")
objConn.Open "DSN=AccessDSN;"
objRS.CursorLocation = 3

'SQL Server DSN
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "DSN=SQLDSN;", strUserName, strPassword
objRecordset.CursorLocation = adUseClient

'Get Access Data or rs1
objRS.Open "SELECT * FROM qryAccessQuery", objConn, 3, 3

'Get SQL Data or rs2
objRecordset.Open "SELECT * FROM tblSQLTable" , objConnection, adOpenStatic, adLockOptimistic

Do While Not objRS.EOF 'Loop through Access recordset
    objRecordset.AddNew 'Add to SQL table
        For Each fld In objRS.Fields
        objRecordset(fld.Name) = fld.Value
        objRecordset("DateField") = strDate
        objRecordset("TimeField") = strTime

'Close Access

'Close SQL

You can do your own looping based on the fields you are checking and what you are checking for. If I had more info I could get more specific.

This is written in VBScript, btw, so will work with VBA perhaps with slight modifications.

I hope this gets you started anyway.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop through 17 tables in RecordSet object didimichael C# 1 July 18th, 2008 06:53 AM
Recordset filter tiyyob Pro VB 6 0 May 24th, 2006 05:33 AM
recordset not showing up on page loop pablohoney Classic ASP Databases 1 December 14th, 2005 06:43 PM
Querying Recordset with a Loop rabu Access VBA 10 December 14th, 2005 04:49 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.