|
-
Oct 10th, 2001, 05:35 PM
#1
How to pass an object? And pass the real thing not only a pointer.
I'd like to fill up an object array with recordsets. Let's say I have
dim aobjArr(1) as object
dim rst as recordset
rst.activeconnection = myConn
rst.source = "SELECT * FROM tblA;"
rst.open
set aobjArr(0) = rst
set datagrid1(0).datasource = aobjArr(0) 'works fine so far
rst.close
rst.source = "SELECT * FROM tblB;"
rst.open
set aobjArr(1) = rst
set datagrid1(0).datasource = aobjArr(0)
set datagrid1(1).datasource = aobjArr(1) 'the two datagrids will be filled with identical data from the second query.
How can I overcome this? How can I pass the real thing and not just a reference? Is it possible to make one object BECOME another one and have all it's properties and when the one object changes the other won't?
Like when I do
set rstA = rstB
as soon as I change rstA, rstB will change too. I don't want that. What do I have to do?
thx,
Helger
-
Oct 10th, 2001, 06:07 PM
#2
Code:
' one way ---------
dim aobjArr(1) as object
dim rst(1) as recordset
rst(0).activeconnection = myConn
rst(0).source = "SELECT * FROM tblA;"
rst(0).open
set aobjArr(0) = rst(0)
set datagrid1(0).datasource = aobjArr(0) 'works fine so far
rst(0).close
<<<<<<<<<<<<<<
rst(1).activeconnection = myConn
rst(1).source = "SELECT * FROM tblB;"
rst(1).open
rst(1).open
set aobjArr(1) = rst(1)
It's too late in the day for me explain why, but with what you were doing you had the recordsets pointing to the same thing, so when you updated the rst (as what you thought was new, you were aslso updating what you thought was old and static. You were using an object pointer - when you change the object in instance B, it also changes instance A - because they point to the same thing.
By the way Dim A as Object creates and object pointer, not an object.
You could also have done Set rst = New Recordset, where the <<< is and not played the array game, if you don't like object arrays.
-
Oct 10th, 2001, 06:09 PM
#3
Thanks I'll try tomorrow. Need to get some sleep first.
Helger
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
|