View Full Version : BETWEEN [Dates on a form]


Gkirkup
02-05-2009, 03:29 PM
I have a query which worked fine with this in the date column:

BETWEEN [Enter the start date] AND [Enter the end date].

I now have to use the two dates from a form, so I have changed the query to:

BETWEEN [Forms]![2 Supplier Quality Report]![StartDate] And [Forms]![2 Supplier Quality Report]![EndDate]

I keep getting syntax error when this is run. The form name is correct, and the two control names are correct. I have tried putting the 'from' and 'to' text in square brackets, but that does not help.
Any ideas?

Robert

John Big Booty
02-05-2009, 05:49 PM
Try;

BETWEEN ([Forms]![2 Supplier Quality Report]![StartDate]) And ([Forms]![2 Supplier Quality Report]![EndDate])

You need to enclose the from and to arguments in parenthesis.

Gkirkup
02-05-2009, 06:35 PM
John: OK, I changed the query to:

Between ([Forms]![2 Supplier Quality Report]![StartDate]) And ([Forms]![2 Supplier Quality Report]![EndDate])

I still get almost the same error message:

Syntax error in query expression 'First([[Forms]]![2 Supplier Quality Report]![StartDate])'

I don't know where the 'First' is coming from. Nor can I see any syntax error.

Robert

John Big Booty
02-05-2009, 06:46 PM
You seem to have enclosed Forms in two sets of square bracket "[" or was that a typo when you posted the message.

Also spaces in object (tables, forms etc.) and controls names will give you no end of grief. This could possibly be one of it's manifestations. Try using underscores and CamelHumping instead.

Are you able to post your DB? The syntax I posted in my earlier reply worked when I trailed it on my scratch DB here :confused:

Gkirkup
02-05-2009, 06:55 PM
John:
No that was not a typo. The error message shows two sets of brackets, even though there is only one in the code. Also the word 'First' is not in the code.
I take your point about not having spaces in form names etc. I will try that.

Robert

ajetrumpet
02-05-2009, 07:02 PM
If I may make an addition here, this is what is supposed to work, as John the Boot man has said:

Between Forms![2 Supplier Quality Report]!StartDate And Forms![2 Supplier Quality Report]!EndDate

Also, this:Between (Forms![2 Supplier Quality Report]!StartDate)could possibly be read like a Procedure call that has arguments in it. That would be my guess. other than that, i have no guesses either...

John Big Booty
02-05-2009, 07:08 PM
Interesting. Have a look at the attached sample. If removing the spaces doesn't work and the sample doesn't help, post a copy of your DB

ajetrumpet
02-05-2009, 07:12 PM
DB2 John? ;) LOL. Looks like you screwed up the first scratch copy, huh? :D Thank goodness for default database names.

John Big Booty
02-05-2009, 07:26 PM
DB2 John? ;) LOL. Looks like you screwed up the first scratch copy, huh? :D Thank goodness for default database names.

No DB1 worked fine, it was full of all sorts of other irrelevant tests. So I just dragged the appropriate tables and so forth into a new DB :p

John Big Booty
02-05-2009, 07:28 PM
Welcome back :D

Gkirkup
02-05-2009, 07:35 PM
Thanks for your help. I am embarrased to find that the error is not in the query at all - even though the error message says 'Syntax error in query expression'.
Here is the situation:
I have a simple form with from/to dates. A print button calls a report. The data source for the report is my query. BUT, on the report I have the from and to dates, referencing the dates on my date entry form. I removed those dates from the report, and the query and report ran perfectly.
So no query problem. This is a report problem.

Robert

John Big Booty
02-05-2009, 07:41 PM
Glad you found the source of your problem.

ajetrumpet
02-06-2009, 05:17 PM
Welcome back :DVery Funny. :rolleyes: