Type Mismatch

  • Thread starter Thread starter Brian
  • Start date Start date
B

Brian

Can anyone tell what's wrong with this code, I have used this method in lots
of forms but for some reason, this just won't work, I get a Type Mismatch
error on the last line.

Private Sub cmdGo_Click()
Dim Db As Database
Dim RsResults As Recordset

Set Db = CurrentDb()
Set RsResults = Db.OpenRecordset("tblResults", dbOpenDynaset)

end sub

any ideas ???
Brian
 
Brian

Your code uses the DAO syntax. You are using A2k or A2K2 where the default
is to use ADO. The solution is to set a reference to DAO (Microsoft DAO 3.x
Object Library). If you're *not* using ADO, you should remove the reference
to it (Microsoft ActiveX Data Objects 2.x Library).

If you need (or want) both, then you must dis-ambiguate variable
declarations such "x As Recordset". Your code declarations would be;

Dim Db As DAO.Database
Dim RsResults As DAO.Recordset

when this is done, you will be able to compile and run without errors

HTH

Andy
 
Hi Brian!

I can't tell you what's wrong but I had the same problem
before...I solved it by using this code instead (it just
wouldn't work with the way I/you used):

Dim MyDB As Database
Dim MyQ As QueryDef

Set MyDB = DBEngine.Workspaces(0).Databases(0)
Set MyQ = MyDB.CreateQueryDef()
MyQ.Name = " a name "
MyQ.SQL = " your sql-question"
MyDB.QueryDefs.Append MyQ
MyQ.Execute
MyQ.Close
MyDB.QueryDefs.Delete " the name you wrote above"

It takes the database you're using at the moment, creates
and runs the sql-question, closes and deletes the question.

Hope this could help you!

Maybe you could help me - I wrote a post before (sender
Maria from Sweden)?

Have a nice 4th of July if you're american!

Cheers
// Maria
 
Thanks Andy,
You were correct, simply being explicit and adding the DAO prefix, fixed it.
Thanks again,
Brian
 
Back
Top