I am programming an application in VBA that uses ODBC and querying for large data sets. I have found that putting the SQL in a string - or concatenated strings - is messy and doesn't seem to work for anything over the standard string length.
I have taken the route of using the query builder and saving the query with parameters. I am attempting to access this query programatically. However, this query has 3 parameters and I am not having luck with articles and answers I have found.
Here is the code:
Dim qdf
Set qdf = CurrentDb.QueryDefs("Kilometers")
qdf.Parameters("startDate").value = startDate
qdf.Parameters("endDate").value = endDate
qdf.Parameters("workshopCode").value = garageRst!ID
Set rs = kpidb.OpenRecordset("Kilometers")
I have the parameters in the sql statement called "Kilometers" like so:
PARAMETERS startDate DateTime, endDate DateTime, workshopCode Text ( 255 );
And in the statement use square brackets to denote the parameters. I also have them set up in the access tool for parameters.
When I run my code, Access is saying that it needs 3 parameters (error 3061)
Is this the way I should be achieving my end goal? What am I doing wrong?
@to each parameter name?