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

Access 2000 Query (access not SQL) with Parameter Need help

Status
Not open for further replies.

CJwater

IS-IT--Management
Mar 26, 2008
34
US
Not really sure how to call an Access query and pass parameters in ADO. My query works, my VBA code does not.
Here's my code any help would be greatly appreciated!

Dim db As Database
Dim rst As Recordset
Dim qdf As QueryDef
Set db = CurrentDb
Set qdf = db.QueryDefs("qry_GetWorksheetFlag")

'GetWorksheetID() is function that gets the current ID
qdf.Parameters(0).Value = GetWorksheetID()
'Set rst = qdf.OpenRecordset error I get here is "Type mismatch"
' not sure which to use neither works
Set rst = CurrentDb.OpenRecordset(QDef, dbOpenDynaset)
Error I get "The Microsoft Jet database engine cannot find the input table or query ''. Make sure it exists and that its name is spelled correctly."

Thanks
CJ
 
Code:
Dim db As Database
Dim rst As [!]DAO.[/!]Recordset
Dim qdf As QueryDef
Set db = CurrentDb
Set qdf = db.QueryDefs("qry_GetWorksheetFlag")
qdf.Parameters(0).Value = GetWorksheetID()  
Set rst = qdf.OpenRecordset

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yes, thank you so much; but could you explain why DAO.Recordset?

Thanks again
CJ
 
Because Recordset is defined in both ADODB and DAO libraries and a QueryDef.Recordset should be DAO, thus the type mismatch error.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top