Openrecordset won't work

G

Guest

I use this technique in another database every day but it won't work in this
one so I set up a test

Private Sub Command1_Click()
Dim db As Database
Dim r As Recordset
Dim strx As String

Set db = CurrentDb
strx = DLookup("Firstname", "Participants", "[FamID]=51")
MsgBox strx
Set r = db.OpenRecordset("SELECT FirstName FROM Participants WHERE FamID=51")

End Sub

The Dlookup works fine but the OpenRecordset gives me this error
Run-time error '13':
Type mismatch

I have checked References and can't find anything wrong.
Any ideas please?
Stephen
 
A

Allen Browne

Both the ADO and DAO libraries have a Recordset object.

If you have ADO as a higher priority than DAO (i.e. above under Tools |
References), you will get an ADO recordset. Since CurrentDb is a DAO object,
it will then fail with a type mismatch.

To explain that you want a DAO recordset, change the 3rd line to:
Dim r As DAO.Recordset

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

message
news:[email protected]...
 

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