|
-
Apr 9th, 2007, 02:23 AM
#1
Thread Starter
Hyperactive Member
How can I equate 2 record sets?
Hi,
Here is how I am connecting to access database:
rs As ADODB.Recordset
rs1 As ADODB.Recordset
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= " & MyAppPath & "\Vehicle_sales.mdb"
cn.Open
Set rs = New ADODB.Recordset
sSql = "SELECT * FROM Payments "
sSql = sSql & "WHERE PO_id = " & POid & " "
sSql = sSql & "AND Cust_id = " & Cid
Set rs = cn.Execute(sSql)
No I want to equate rs1 = rs. How can I do that?
Thanks in advance.
-
Apr 9th, 2007, 02:34 AM
#2
Lively Member
Re: How can I equate 2 record sets?
you are trying to equate two recordsets.
that means you want the same result-set in the two recordset..
you have already done this..
Set rs = cn.Execute(sSql)
you can repeate the same with different recordset..
Set rs1 = cn.Execute(sSql)
-
Apr 9th, 2007, 03:20 AM
#3
Re: How can I equate 2 record sets?
Check this for comparing two ADODB recordset
Code:
Do While rs1.EOF = False
Do While rs2.EOF = False
If Trim(rs1("Value")) <> Trim(rs2("Value")) Then
Else
rs2.MoveNext
Exit Do
End If
Loop
rs1.MoveNext
Loop
-
Apr 9th, 2007, 05:19 AM
#4
Thread Starter
Hyperactive Member
Re: How can I equate 2 record sets?
Thanks for a quick reply guys.
Here is what I am trying to do. My rs record set is defined as private in my form. I am reading a record in rs record set in one procedure then after assigning few fields out the rs record set to the text boxes I am calling another procedure where rs1 record set is defined as a local for this procedure and I HAVE TO read a different table but in the same rs record set so before I do that I want to save all the values of rs record set into the rs1 record set and at the end of this procedure put back all the values into rs record set from the rs1 record set.
How can I achieve this?
-
Apr 9th, 2007, 05:24 AM
#5
Re: How can I equate 2 record sets?
Im confused...what do you want to do actually...
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Apr 9th, 2007, 05:29 AM
#6
Re: How can I equate 2 record sets?
Loop through rs recordeset to put/save values in rs1 defined on same table.
-
Apr 9th, 2007, 06:07 AM
#7
Thread Starter
Hyperactive Member
Re: How can I equate 2 record sets?
Amrta,
Can you please give me an example of how to loop thru to save values? I am getting errors the way I am trying to loop thru.
Thanks in advance.
-
Apr 9th, 2007, 06:10 AM
#8
Re: How can I equate 2 record sets?
What you have tried just show me ??
-
Apr 9th, 2007, 10:49 AM
#9
Re: How can I equate 2 record sets?
Look in the ADO help for the Clone method. There's an example too.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Apr 9th, 2007, 08:47 PM
#10
Thread Starter
Hyperactive Member
Re: How can I equate 2 record sets?
Amrita,
I tried the following 2 ways which did not work for me.
1. rs1 = rs
2. For I = LBound(rs.fields) to UBound(rs.fields)
rs1.fields(I) = rs.fields(I)
Next I
Please tell me how should I be doing this?
Thanks.
-
Apr 10th, 2007, 03:15 AM
#11
Re: How can I equate 2 record sets?
Check this (just an example)!
Code:
Dim rs As New ADODB.Recordset
Dim rs1 As ADODB.Recordset
Set rs = conn.Execute("Select EmpId From tblEmp")
Set rs1 = New Recordset
rs1.Fields.Append "EmpId", adInteger
rs1.Open
Do While rs.EOF() = False
rs1.AddNew
rs1.Fields("EmpId").Value = rs("EmpId")
rs1.Update
rs.MoveNext
Loop
-
Apr 10th, 2007, 04:31 PM
#12
New Member
Re: How can I equate 2 record sets?
If I understand you . It is Easy
I needed to take the same values in two Recordsets of Diferent kind of declaration (Public, Private) and i use it :
Code:
Public Function buscaTesisRel(strCveGen As String, strTipoDoctoOrigen As String) As Recordset
Set buscaVotoRel = recRet
Set recGlobalRelacion = buscaTesisRel(strSentenciaSeleccionada, GstrTipoDocto)
'FIRST YOU NEED TO SET THE RECORDSET TO NOTHING
Set recGlobalRelacion = Nothing
In your case do :
Set rs1= Nothing
Set rs1=rs
Warning: I used this kind of Recordset declaration:
Dim recRet As New Recordset
I think that ADODB.Recodset is the same
Bye
-
Apr 10th, 2007, 11:50 PM
#13
Re: How can I equate 2 record sets?
 Originally Posted by Newtester
Thanks for a quick reply guys.
Here is what I am trying to do. My rs record set is defined as private in my form. I am reading a record in rs record set in one procedure then after assigning few fields out the rs record set to the text boxes I am calling another procedure where rs1 record set is defined as a local for this procedure and I HAVE TO read a different table but in the same rs record set so before I do that I want to save all the values of rs record set into the rs1 record set and at the end of this procedure put back all the values into rs record set from the rs1 record set.
How can I achieve this?
Rather than going through all the trouble of passing data back and forth between the recordsets, why not just have each communicate directly with the database (leaving them unaware of each other) and have each recordset requery the database so their data is up to date....
Why not a straightforward implementation? Let me guess... your using data bound controls aren't you?
-
Apr 11th, 2007, 08:32 AM
#14
Re: How can I equate 2 record sets?
 Originally Posted by Newtester
Amrta,
Can you please give me an example of how to loop thru to save values? I am getting errors the way I am trying to loop thru.
What are the errors?
 Originally Posted by NEOMEGAX
Warning: I used this kind of Recordset declaration:
Dim recRet As New Recordset
It should be:
Code:
Dim recRet As ADODB.Recordset 'to initialize
'then
Set recRet = New ADODB.Recordset 'to actually use it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|