Passing variables to make table query

PiedPiper70

Registered User.
Local time
Today, 21:14
Joined
Oct 21, 2012
Messages
115
Access 2010 vba - I'm trying to pass a start date and end date to a date field in a make table query, and use the 'between' operator on that date field.

So I have a criteria on the date field like this "Between [dtStart] and [dtEnd]" and if I run the query manually it asks for 2 values and then works fine.

Here's the code I'm trying to run:-
Set qdef = db.QueryDefs("qryTest")
qdef.Parameters("dtStart") = StartDate1
qdef.Parameters("dtEnd") = EndDate1
Set rs1 = qdef.OpenRecordset(dbOpenDynaset, dbSeeChanges)

and I get the error "3219 Invalid Operation" on the last line.

Am I doing something stupid!!

Thanks for any help
 
Are you entering your dates as MM/DD/YYYY ??

Also you are talking about a make table query, you cannot open an action query as a recordset. Instead you use the method Execute to run it....
 
Thanks namliam - all sorted.
 

Users who are viewing this thread

Back
Top Bottom