Results 1 to 14 of 14

Thread: How can I equate 2 record sets?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    476

    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.

  2. #2
    Lively Member
    Join Date
    Mar 2007
    Posts
    78

    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)

  3. #3
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    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

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    476

    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?

  5. #5
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    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.


  6. #6
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    Re: How can I equate 2 record sets?

    Loop through rs recordeset to put/save values in rs1 defined on same table.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    476

    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.

  8. #8
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    Re: How can I equate 2 record sets?

    What you have tried just show me ??

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    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

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    476

    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.

  11. #11
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    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

  12. #12
    New Member
    Join Date
    Sep 2005
    Posts
    5

    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

  13. #13
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: How can I equate 2 record sets?

    Quote 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?

  14. #14
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How can I equate 2 record sets?

    Quote 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?
    Quote 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
  •  



Click Here to Expand Forum to Full Width