Form opening report, custom dates, error

G

Geoff

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?
 
G

Geoff

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.
 
O

Ofer Cohen

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 & "#"
 
G

Geoff

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?
 
O

Ofer Cohen

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?
 
Top