R
Robert
?
Robert
Robert
Robert said:
Dirk Goldgar said:A recordsetclone is a "clone" of a recordset -- that is, a recordset
object that is created by copying an existing one. The Recordset object,
in both the DAO and the ADO object libraries, has a Clone method to create
such an object. An Access form has a RecordsetClone proeprty, which
returns a clone of the form's recordset -- not the form's recordset
itself, but a copy of it.
The handy thing about the recordset clone is that its Bookmark proeprty is
compatible with that of its parent recordet, so you can synchronize the
two by matching bookmarks. Most commonly this is used to find a record in
the form's RecordsetClone, and then position the form to that record by
setting the form's Bookmark property to the recordsetclone's Bookmark.
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)
Douglas J. Steele said:
An Access form has a RecordsetClone proeprty, which returns a
clone of the form's recordset -- not the form's recordset itself,
but a copy of it.
David W. Fenton said:Er, to be more precise, the RecordsetClone *is* a clone of the
recordset and can be operated on directly, like any other recordset
or recordset clone.
It can also be used as a FUNCTION that returns a
pointer to itself (not a new clone of the form's RecordsetClone).
It sounds to me as though you code like this:
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
[do something with the rs variable you've just created]
Set rs = Nothing
Instead, it's *much* easier and cleaner to do this:
With Me.RecordsetClone
[do something with the actual RecordsetClone]
End With
No cleanup, no variable declaration, not SET operations, no extra
memory allocated for the pointer to an object that already exists in
memory and has an object that already exists for using.
Uh, that's pretty much what I said.
I don't think that's true any more. In earlier versions of
Access, as I recall, a single clone of the form's recordset would
be created the first time the RecordsetClone property was
interrogated,
and then that same clone
would be supplied to all future requests for the property until
the form was closed. However, in more recent versions, a new
clone of the form's recordset is taken each time the
RecordsetClone property is asked for.
This
has meant that code like this:
Me.RecordsetClone.FindFirst "ID = " & varIDWanted
Me.Bookmark = Me.RecordsetClone.Bookmark
... which used to work fine, no longer gives the desired result,
because the second RecordsetClone is not positioned at the same
record as the first. Instead, we have to write:
With Me.RecordsetClone
.FindFirst "ID = " & varIDWanted
Me.Bookmark = .Bookmark
End With
It sounds to me as though you code like this:
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
[do something with the rs variable you've just created]
Set rs = Nothing
I haven't the faintest idea what would make you think that.
You're jumping to a conclusion that is not supported by any
evidence.
Instead, it's *much* easier and cleaner to do this:
With Me.RecordsetClone
[do something with the actual RecordsetClone]
End With
I agree. See any of umpty-zillion code snippets I've posted.
No cleanup, no variable declaration, not SET operations, no extra
memory allocated for the pointer to an object that already exists
in memory and has an object that already exists for using.
However, I think you're overstating the case a bit. If I write
...
With Me.RecordsetClone
' Do stuff
End With
An object reference still has to be retrieved, stashed in a local
memory location, and then freed up when the block exits. I don't
see any reason that what goes on behind the scenes would be
significantly different from what goes on if I write:
Dim rs As Recordset
Set rs = Me.RecordsetClone
' Do stuff
Set rs = Nothing ' or just wait for procedure clean-up
Oh, I suppose there's initialization and cleanup code involved
when you use a local variable that may not be when you use the
With block, but I think local memory is still going to be
allocated for the object pointer either way.
I would point out that the RecordSet clone of a form or report is
a DAO object in all versions of Access, even in 2K and XP where
the default library was ADO. This caused great confusion as you
might imagine.
David W. Fenton said:No, it's not at all the same thing. You said the property returns a
clone, just as Me.Recordset.Clone would. But instead,
.RecordsetClone is a clone that already exists, and is created when
the form's recordset is populated.
I think it's created when the form's recordset is created.
But you don't have to code it. That's a good thing, no?
I think your description of a RecordsetClone is misleading as it
*does* exists before you call it. At least, according to MichKa.
I didn't say it returns a *fresh* clone, just that it returns a
clone, which we both agree it does.
So my original statement is true as written.
However, I did in fact think that, in recent versions, the
RecordsetClone property returned a new clone each time. I've
tested that now and found that I was wrong:
Set rs1 = Me.RecordsetClone
Set rs2 = Me.RecordsetClone
Debug.Print rs1 Is rs2 ' prints True
If ADPs behave differently, perhaps that's where my incorrect
understanding came from (though I've never done more than dabble
with ADPs).
That could be, but is there any reason to think that it's not
created the first time the property is interrogated?
To my mind, that would be more
efficient. Why create the clone if it's not going to be used?