Creating an independent instance of a recordset 
Author Message
 Creating an independent instance of a recordset

I should know what's wrong here but I am having "one of those days".  Excuse
the "newbishness" here.

I have a recordset "rs" which is open and I want to set it to another
variable lets say "rs1". I want to leave "rs1" open so I can manipulate it
independent of "rs", then close "rs" and then change rs.Source, open it back
up as a new/different recordset, set THAT recordset to "rs2", and do it all
again for "rs3", etc. etc. "rs" acts as the temporary recordset inbetween
the others. But I understand that VB really creates a reference to "rs" and
when I change "rs", "rs1", "rs2" and "rs3" will all be the exact same.  So
when I close rs the second time to make "rs2", I also close "rs1".  I think
I am using the keyword NEW appropriately but  it gives me run-time errors.
Please help with a quick rundown on how this should be approached. Thank
you.

-Sid



Sun, 27 Jun 2004 02:08:11 GMT
 Creating an independent instance of a recordset

I think "clone" will do that for you ie rs2 = rs.Clone. You can delete the
original and the clone will remain intact. You also have options on the lock
type.


Quote:
> I should know what's wrong here but I am having "one of those days".
Excuse
> the "newbishness" here.

> I have a recordset "rs" which is open and I want to set it to another
> variable lets say "rs1". I want to leave "rs1" open so I can manipulate it
> independent of "rs", then close "rs" and then change rs.Source, open it
back
> up as a new/different recordset, set THAT recordset to "rs2", and do it
all
> again for "rs3", etc. etc. "rs" acts as the temporary recordset inbetween
> the others. But I understand that VB really creates a reference to "rs"
and
> when I change "rs", "rs1", "rs2" and "rs3" will all be the exact same.  So
> when I close rs the second time to make "rs2", I also close "rs1".  I
think
> I am using the keyword NEW appropriately but  it gives me run-time errors.
> Please help with a quick rundown on how this should be approached. Thank
> you.

> -Sid



Sun, 27 Jun 2004 04:54:30 GMT
 Creating an independent instance of a recordset
I think that your method of creating multiple recordsets needs work.
A recordset is a complex object that you wouldn't really want to make
a copy of.  It's more simple to just apply different Source strings to
the recordset objects.  For instance:

Private cn1 As ADODB.Connection, rs1 As ADODB.Recordset, rs2 As
ADODB.Recordset, rs3 As ADODB.Recordset

Private Sub Tmp_Proc()
  Dim sSQL$

  Set cn1 = New ADODB.Connection
      cn1.Open CONNECTION_STRING  

  sSQL = "select * from tblA"
  Set rs1 = New ADODB.Recordset
  Set rs1.ActiveConnection = cn1
      rs1.Open sSQL

  sSQL = "select * from tblB"
  Set rs2 = New ADODB.Recordset
  Set rs2.ActiveConnection = cn1
      rs2.Open sSQL

  sSQL = "select * from tblC"
  Set rs3 = New ADODB.Recordset
  Set rs3.ActiveConnection = cn1
      rs3.Open sSQL

  ...do other stuff...

End Sub

-Wayne Bloss, Programmer.

Quote:

> I should know what's wrong here but I am having "one of those days".  Excuse
> the "newbishness" here.

> I have a recordset "rs" which is open and I want to set it to another
> variable lets say "rs1". I want to leave "rs1" open so I can manipulate it
> independent of "rs", then close "rs" and then change rs.Source, open it back
> up as a new/different recordset, set THAT recordset to "rs2", and do it all
> again for "rs3", etc. etc. "rs" acts as the temporary recordset inbetween
> the others. But I understand that VB really creates a reference to "rs" and
> when I change "rs", "rs1", "rs2" and "rs3" will all be the exact same.  So
> when I close rs the second time to make "rs2", I also close "rs1".  I think
> I am using the keyword NEW appropriately but  it gives me run-time errors.
> Please help with a quick rundown on how this should be approached. Thank
> you.

> -Sid



Sun, 27 Jun 2004 09:17:06 GMT
 
 [ 3 post ] 

 Relevant Pages 

1. Creating an independent instance of a recordset

2. Copying existing instance to create a new instance

3. ADO AsyncExecute creates independent connections

4. best dbase for creating independent programs royalty-free?

5. Creating a new recordset from an existing recordset

6. Create a RecordSet within a RecordSet in VC++ ??

7. Recordset ReOpen create a new recordset ptr?

8. Query Recordset, Create Summary/New Recordset

9. Create new recordset from another recordset

10. attaching a recordset created in code to the recordsets collection

11. How do I create a recordset based on an existing recordset

12. Using a recordset to create another recordset


 
Powered by phpBB® Forum Software