Passing a between statement to a query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all,

I am trying to pass the date range to a query from calendars on a form. It
needs to be an inbetween statement. I have tried using something like this
it the criteria:

between [txCal1] and [txCal2]. This did not work. I also tried just
passing just a string to the query. Somthing like this:
Criteria =[txResults]
vb string
txResults = "Between #" & txCal1 & "# and #" & txCal2 & "#"

How can I use the between statement in a query that is varible
 
You can use the SQL property of the query to rewrite the query,
concatenating in the desired string.

Example:
CurrentDb.QueryDefs("MyQuery").SQL = "Select .... WHERE FieldName " &
txResults & ";"

The other option is to set the criteria in the query to refer to the form
controls you have listed as Parameters of the query.

Example:
PARAMETERS [Forms]![MyForm]![txCal1] DateTime, [Forms]![MyForm]![txCal2]
DateTime;
SELECT ....
WHERE FieldName Between [Forms]![MyForm]![txCal1] And
[Forms]![MyForm]![txtCal2]
 
Back
Top