Solved

How can ADO recordsets be combined?

Posted on 2000-02-28
10
313 Views
Last Modified: 2013-11-26
I'm using VB6 with ADO and an Access 2000 database.  I have two ADODB recordsets with only one field (MfgCode) in common that I need to combine into one recordset.  Does anyone have an example of how to do this?  I cannot use a SQL statement to write another query to generate the desired recordset.  I need to combine the existing recordsets into a new recordset where the mfgcode fields of the two recordsets match.
0
Comment
Question by:CrazyFox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 9

Accepted Solution

by:
samopal earned 100 total points
ID: 2566175
Why you cannot use SQL query? But if you cannot, then....

Rs1 - 1st Recordset
Rs2 - 2nd Recordset
Rs - result Recordset

rs1.movefirst
do while not rs1.eof
 rs.addnew
 rs!MfgCode = rs1!MfgCode
 rs.Update
 rs1.MoveNext
Loop

rs2.MoveFirst
do while not rs2.eof
  rs.find "MfgCode = " & rs2!MfgCode
  if rs.eof then
    rs.addnew
    rs!MfgCode = rs2!MfgCode
    rs.Update
  end if
 rs2.MoveNext
loop
0
 

Author Comment

by:CrazyFox
ID: 2566341
I tried your example and got the following error on the line rs.addnew:

Run-Time Error '3704'
The operation requested by the application is not allowed if the object is closed.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2566407
Your new recordset must be declared this way:

Dim rstMemory As ADODB.Recordset

    Set rstMemory = New ADODB.Recordset
    With rstMemory
        .CursorLocation = adUseClient
        .LockType = adLockPessimistic
        .Fields.Append "MfgCode", adVarChar, 50
        .Open
    End With

Once this part is done, you can use the AddNew method on this recordset.
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

Author Comment

by:CrazyFox
ID: 2566434
emoreau,
That worked, but how do I get more than just the mfgcode field in the resulting recordset?  What I really need is all the fields from both recordsets in the result recordset where the mfgcodes are the same.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2566462
You can use «.Fields.Append» to add other fields.

But why can't you do it from your database in a query like this:
Select Table1.*, Table2.*
From Table1, Table2
Where Table1.mfgcode = table2.mfgcode
0
 

Author Comment

by:CrazyFox
ID: 2566476
I can't use the query because sometimes table2 will be empty.  It is filled in with optional user comments during runtime and these comments are then used elsewhere in the app by user generated reports.

If it is empty, then the query returns no results.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2566495
What is your database engine? You can use a left join.
0
 

Author Comment

by:CrazyFox
ID: 2566509
Provider=Microsoft Jet 4.0 OLE DB Provider
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2566534
So you use Access. Your query may look like this:

Select Table1.*, Table2.*
From Table1 LEFT JOIN Table2
ON Table1.mfgcode = table2.mfgcode
0
 

Author Comment

by:CrazyFox
ID: 2566596
That still gives me an empty recordset.  I checked the data and there should be two matching records from the tables.  I'll try the fields.append
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question