I'm trying to open a report with date field between two dates (dateFrom & dateTo) which comes from the textboxes in a form.
dateFrom = Forms!formOptions!txtDateFrom.Value
dateTo = Forms!formOptions!txtDateTo.Value
Have tried:
(Edit:)
with and without the '#' around the dateFrom and dateTo variables
& with and without the [] around the field name, and still cannot get this to work.
When I try this code:
strCriteria = "[ActionTime] >= '" & dateFrom & "' And [ActionTime] <= '" & dateTo & "'"
DoCmd.OpenReport "reportLog", acViewReport, , strCriteria
An 'Enter a parameter value' dialog will popup, I've checked the control source of the report & the field name is correct & there are no sorting or grouping happening either.
And when I put a pair of extra ' ' around the field name in the above code to be:
strCriteria = "'[ActionTime]' >= '" & dateFrom & "' And '[ActionTime]' <= '" & dateTo & "'"
DoCmd.OpenReport "reportLog", acViewReport, , strCriteria
The report opens normally but instead of just the record between the dates, all of the records appear.
Have also tried using the WhereCondition:
DoCmd.OpenReport "reportLog", acViewReport, , WhereCondition:="'[ActionTime] >= #" & dateFrom & "# AND [ActionTime] <= #" & dateTo & "#'"
And the report opens normally but with all the records, not following the WhereCondition.
I don't know which part of this coding is false, have referred to other sites but still can't detect what's exactly wrong. Would be grateful for any guidance. Thanks in advance.