Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with OpenRecordset

Status
Not open for further replies.

Leeeon

Programmer
Mar 24, 2003
19
0
0
GB
Hi

I'm using Access XP, and having a problem with the OpenRecordSet method. If I try the code below, I keep getting a type mismatch error at the 'Set MyRs' line.

Function testit()

Dim MyDb As Database
Dim MyRs As Recordset
Set MyDb = CurrentDb()

Set MyRs = MyDb.OpenRecordset("MyQuery")

I've set the reference to the MS DAO 3.6 library, so can't understand why I'm getting this error. I've put the identical code into one of my other databases and it works fine.

I'm totally confused now!

Any help would be much appreciated.

Thanks

LeonH




End Function
 
Looking at another thread has given me the answer:

Instead of

Dim MyRs as Recordset

I needed to use

Dim MyRs as DAO.Recordset

Still seems strange that my other databases worked ok though!?

 
Default reference in Access XP is ADO 2.1 and probably is listed before your DAO 3.6 selection

So decleare

Dim MyDb As DAO.Database
Dim MyRs As DAO.Recordset

This is for AD0 2.x versions.

Dim MyRs As ADODB.Recordset

 
Dim MyRs As DAO.Recordset

Be sure to have the Microsoft DAO 3.x Object Library referenced:
menu Tools -> References ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for quick replies.

You were right JerryKlmns. The ADO 2.1 reference was listed first and so had priority.

My other databases were converted from Access 97 to XP, and so didn't have the ADO 2.1 reference, hence why they didn't require the DAO.Recordset ref.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top