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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type Mismatch When Opening Recordset 1

Status
Not open for further replies.

CptCrusty1

Programmer
Feb 17, 2005
216
US
I'm trying to run some real simple code at home. I've used this before at work but can't make it function at home. Really simple example:

DIM rs as Recordset
DIM db as Database
DIM strSQL as String

set db = CurrentDb()

strSQL = "SELECT * FROM tblMyTable"

set rs = db.OpenRecordset(strSQL, dbOpenDynaset)


This is as far as my code gets. The "set rs = ....." statement always always always generates a "TYPE Mismatch" error. I've checked my reference libraries in the Code Editor and my DAO (3.6), and ADO (2.7) libraries are set. I can't figure out for the life of me why this won't work on my two computers at home, but will work on my PC at work. Please help.

Thanks.
Rich.
 
Try:

Code:
[blue]DIM rs as DAO.Recordset
DIM db as DAO.Database[/blue]
DIM strSQL as String

set db = CurrentDb()

strSQL = "SELECT * FROM tblMyTable"

set rs = db.OpenRecordset(strSQL, dbOpenDynaset)

Because you have both ADO and DAO selected in your references, the library that is highest in the list will run by default where the functionality exists in both libraries.

I'm guessing that the ADO library is higher in your reference list than the DAO library. By explicitly declaring your variables, you force the correct Library to run.

HTH
Lightning
 
ARGUH!!!! I feel so STUPID... I have them both checked AND ADO apparently likes being on top. I had to move it, but then... I explicity declared the DAO like you said. I guess I have a new wrinkle in my brain... Thanks.. jeez ... its 11pm here in Houston, Tx... where the heck are you to be checking this stuff regularly....

Stars for you dude..

Thx.
 
Canberra Australia, where it currently 4.00pm

Glad it helped!

Cheers
Lightning
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top