Form opening report, custom dates, error

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

Guest

I am opening a report with the following code in a form:

strCriteria = "Between #" & tbFrom & "# and #" & tbTo & "#"
DoCmd.OpenReport "rptDefective", acViewPreview, , strCriteria

tbFrom and tbTo are text boxes on the opening form.

When I open the report, I get the error:

Syntax error (missing operator) in query expression '(Between
#5/10/2006# and #5/30/06#)'.

For the life of me, I can't see the error. The Where works in SQL. What am I
doing wrong?
 
Geoff said:
For the life of me, I can't see the error. The Where works in SQL. What am I
doing wrong?
That's because I'm an idiot and for got to tell Access what field to compare
to the criteria.
 
In the criteria line you need to add the date field name in the table that
you use the filter on

Yours
strCriteria = "Between #" & tbFrom & "# and #" & tbTo & "#"

Need to be
strCriteria = "[DateFieldName] Between #" & tbFrom & "# and #" & tbTo & "#"
 
Thanks. IO realized that mere seconds after posting the question. I'm a
little rusty and that was a rookie mistake!

Ofer Cohen said:
In the criteria line you need to add the date field name in the table that
you use the filter on

Yours
strCriteria = "Between #" & tbFrom & "# and #" & tbTo & "#"

Need to be
strCriteria = "[DateFieldName] Between #" & tbFrom & "# and #" & tbTo & "#"

--
Good Luck
BS"D


Geoff said:
I am opening a report with the following code in a form:

strCriteria = "Between #" & tbFrom & "# and #" & tbTo & "#"
DoCmd.OpenReport "rptDefective", acViewPreview, , strCriteria

tbFrom and tbTo are text boxes on the opening form.

When I open the report, I get the error:

Syntax error (missing operator) in query expression '(Between
#5/10/2006# and #5/30/06#)'.

For the life of me, I can't see the error. The Where works in SQL. What am I
doing wrong?
 
Trust me, it happen to all of us.

--
Good Luck
BS"D


Geoff said:
Thanks. IO realized that mere seconds after posting the question. I'm a
little rusty and that was a rookie mistake!

Ofer Cohen said:
In the criteria line you need to add the date field name in the table that
you use the filter on

Yours
strCriteria = "Between #" & tbFrom & "# and #" & tbTo & "#"

Need to be
strCriteria = "[DateFieldName] Between #" & tbFrom & "# and #" & tbTo & "#"

--
Good Luck
BS"D


Geoff said:
I am opening a report with the following code in a form:

strCriteria = "Between #" & tbFrom & "# and #" & tbTo & "#"
DoCmd.OpenReport "rptDefective", acViewPreview, , strCriteria

tbFrom and tbTo are text boxes on the opening form.

When I open the report, I get the error:

Syntax error (missing operator) in query expression '(Between
#5/10/2006# and #5/30/06#)'.

For the life of me, I can't see the error. The Where works in SQL. What am I
doing wrong?
 
Back
Top