DAO Execute query with parameters

DylansStrings

New member
Local time
Today, 12:38
Joined
Sep 12, 2012
Messages
4
Hi
I'm using access 2003.
I want to execute a make table query saved in another access database. I use the DAO method below but the query has 2 input parameters and I want to pass these with the db.Execute method below. Is this possible?

Thanks



Code:
Dim db As DAO.Database
Set db = DBEngine.Workspaces(0).OpenDatabase("C:\Mydatabase.mdb")
db.Execute "MyQuery", dbFailOnError
Set db = Nothing
 
Thanks figured it out with QueryDef
Code:
Dim db As DAO.Database
Dim MyQueryDef As DAO.QueryDef
Set db = DBEngine.Workspaces(0).OpenDatabase("C:\Mydatabase.mdb")
Set MyQueryDef = db.QueryDefs("MyQuery")

With MyQueryDef
.Parameters("[Year]") = 2012
.Parameters("[Month]") = 8
End With
MyQueryDef.Execute
Set db = Nothing
 

Users who are viewing this thread

Back
Top Bottom