Problem with RecordsetClone

P

plh

When I run, or I should say, try to run, the following, I get a type mismatch
error on the line:

Set rst = Me.RecordsetClone

This is very puzzling since it is copied almost verbatim from the help files,
and I have done this sort of thing before. There is something I am just not
seeing! Any help would be greatly appreciated!

Thanx,
-plh

Private Sub cmdCloseAndPassValue_Click()
On Error GoTo Err_cmdCloseAndPassValue_Click
Dim rst As Recordset

Set rst = Me.RecordsetClone


Set varBookmark = rst.Bookmark
'rs = Nothing


DoCmd.OpenForm "frmToolAssems", acNormal, , , , , OpenArgs & ";" &
txtCurrTool.Value

DoCmd.Close acForm, "frmTools"

Exit_cmdCloseAndPassValue_Click:
Exit Sub

Err_cmdCloseAndPassValue_Click:
MsgBox Err.Description
Resume Exit_cmdCloseAndPassValue_Click

End Sub
 
J

John Griffiths

I'm guessing here but if rst is of type DAO,Recordset and
Me.RecordsetClone if of type ADO.Recordset (or vice versa)
then I guess other wise ok looking code is going to cause problems.

If you suspect this check in the object inspector to see if
both "ADODB" and "DAO" are registered.

I look forward to hearing the real culprit - John
 
V

Van T. Dinh

In MDB, the RecordsetClone is a DAO Recordset. In ADP, it is an ADO
Recordset.

If you use A2000 or later with MDB, check:

1. Microsoft DAO 3.6 Object Library is included in the References.
2. If you don't use ADO code, remove the Reference Microsoft ActiveX Data
Object (ADO) 2.x Library.
3. If you want to leave both DAO & ADO Library in the References, you need
to disambiguate the dim statement like:

Dim rst As DAO.Recordset

The problem is likely that you have ADO (or both ADO & DAO Library and ADO
is set on higher priority) so when you declared Recordset, it is default to
ADO Recordset while you actually need DAO Recordset.

Both DAO and ADO have the Recordset Object but DAO Recordset and ADO
Recordset are not compatible. Hence, you got the "Type Mismatch" error.

BTW, I hope it is a partial code you posted. I coundn't see you used the
Recordset or its BookMark anywhere.
 
P

plh

Thanks very much -- also thanks to Mr. Griffiths. I'll try that on Monday.
And in answer to you question: It is just on routine among many.
"Set varBookmark = rst.Bookmark" is intended to store the present position in
varBookmark which is in a Module so it sticks around after this routine
terminates & I can get it back later and return to the same record, when I
reopen the form. At least that's the idea. Haven't tried it yet, because the
type mismatch error was preventing from getting to that point.
-plh.
 
D

Dirk Goldgar

plh said:
Thanks very much -- also thanks to Mr. Griffiths. I'll try that on
Monday. And in answer to you question: It is just on routine among
many. "Set varBookmark = rst.Bookmark" is intended to store the
present position in varBookmark which is in a Module so it sticks
around after this routine terminates & I can get it back later and
return to the same record, when I reopen the form. At least that's
the idea. Haven't tried it yet, because the type mismatch error was
preventing from getting to that point. -plh.

PMFJI, but you won't be able to do what you describe. You can't use a
bookmark saved from one recordset on anything but that same recordset or
its clone (or a form bound to that recordset). If you close and reopen
the form (even though it has the same recordsource), its recordsource is
queried fresh and the resulting recordset isn't the same as the original
recordset from which you saved the bookmark.

If you want to relocate to a particular record in this manner, you must
save that record's primary key (or some other unique value), and then
find that key again in the form's recordset.
 
V

Van T. Dinh

Agree with Dirk's advice 100% ...

In fact, that's the reaon I wondered about the use of the Recordset in the
posted code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top