Parameter range in DoCmd.OpenReport

J

JimAA

Bear with me, I'm really new to this. I'm setting up a form in Access 2003
where a user would select a start year and an end year to open a report based
on a query for sales during that range of years. I can't get the code to
work. This is the code that I've attached to a command button on the form:
DoCmd.OpenReport "Jobs by Sales Rep (all)1", acViewPreview, , "[Fiscal Year]
=#" & Me.CboStartYear & "And <=#" & Me.CboEndYear & "#"
What is wrong with it?
Thanks,
Jim
 
J

Jim Burke in Novi

There's a few things wrong that I can see. First off, in your criteria, add
the word BETWEEN at the beginning, and get rid of the >= and <= operators.
Also, you're missing an # for the format you have. FOr the format you have
you would use

"[Fiscal Year] BETWEEN #" & Me.CboStartYear & "# And #" & Me.CboEndYear & "#"

However, if you have a field that is only a year, then it should not be
treated as a date, but as an Integer type variable, so you shouldn't even
have the #'s. If the Year is an Integer (or Long) value it would just be

"[Fiscal Year] BETWEEN " & Me.CboStartYear & " And " & Me.CboEndYear

JimAA said:
Bear with me, I'm really new to this. I'm setting up a form in Access 2003
where a user would select a start year and an end year to open a report based
on a query for sales during that range of years. I can't get the code to
work. This is the code that I've attached to a command button on the form:
DoCmd.OpenReport "Jobs by Sales Rep (all)1", acViewPreview, , "[Fiscal Year]
=#" & Me.CboStartYear & "And <=#" & Me.CboEndYear & "#"
What is wrong with it?
Thanks,
Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top