Between -- And two dates

G

Guest

My Access 2003 query with criteria to act onstart and end dates for a report:

I created Unbound Form with Unbound Start Date and EndDate. It calls a Macro
which calls a report.
I created Report which has Record Source to Query
I created a Query which has following Criteria:
Between [StartDate] And [EndDate]

Instead of bringing up the Form, it brings up two "Enter Value" windows. I
cannot get it to call the Form.

I have done this many times in prior versions of Access. Will apprecuate
suggestions as to what I may have missed.

(e-mail address removed)
 
G

Guest

The call from the query to a field in a form is different

Between Forms![FormName]![StartDate] And Forms![FormName]![EndDate]
 
G

Guest

If Ofer's solution does not quite work, you may need to enclose the
references to the form controls with # so the query will understand it is a
date. This assumes the fields in the table are date data types.

Between "#" & Forms![FormName]![StartDate] & "#" And "#" &
Forms![FormName]![EndDate] & "#"
 
G

Guest

As Ofer has said you need to use fully qualified references to the controls
on the form as the parameters. With date/time parameters its also advisable
to declare them as such, otherwise a value entered in the form in short date
format can be wrongly interpreted by Access as an arithmetical expression.
This won't cause an error as date/time values are stored as floating point
numbers so the stored number would be compared with the result of the
arithmetical expression, but would give the wrong result. Declaring the
parameters as DateTime also allows for differences in date formatting
internationally.

A further point regarding date ranges is that the BETWEEN….AND operator will
not return any rows where the values in the date field are on the last day of
the range and include a non-zero time of day. There is no such thing as a
date without a time of day in Access, and sometimes non-zero times of day can
be there unseen (a common culprit is the inappropriate use of the Now()
function as a default value). While this can be prevented with a suitable
constraint on the column in the table definition, this is rarely done in my
experience, so its prudent to play safe. This is done by restricting the
result to dates on or after the start date and before the day after the end
date.

So, putting all this together the query would look something like this:

PARAMETERS
Forms!MyForm!StartDate DATETIME,
Forms!MyForm!EndDate DATETIME;
SELECT *
FROM MyTable
WHERE MyDate >= Forms!MyForm!StartDate
AND MyDate < Forms!MyForm!EndDate +1;

In query design view you declare parameters by selecting parameters from the
Query menu and entering the two parameters and their data types in the
dialogue. The range can be defined in design view by entering the following
as the criterion for the MyDate column:
= Forms!MyForm!StartDate AND MyDate < Forms!MyForm!EndDate +1

After you save the query you'll probably find Access has shifted things
round a bit when you reopen it in design view. The end result will be the
same, however.

Ken Sheridan
Stafford, England

bobn3faw said:
My Access 2003 query with criteria to act onstart and end dates for a report:

I created Unbound Form with Unbound Start Date and EndDate. It calls a Macro
which calls a report.
I created Report which has Record Source to Query
I created a Query which has following Criteria:
Between [StartDate] And [EndDate]

Instead of bringing up the Form, it brings up two "Enter Value" windows. I
cannot get it to call the Form.

I have done this many times in prior versions of Access. Will apprecuate
suggestions as to what I may have missed.

(e-mail address removed)
 
G

Guest

As date literals assume a US or otherwise internationally unambiguous date
format that would give the wrong results in Europe or anywhere else using
non-US date formatting unless the format in which the parameter values were
entered was otherwise internationally unambiguous. The best way is to
declare the parameters as DateTime.

Ken Sheridan
Stafford, England

Klatuu said:
If Ofer's solution does not quite work, you may need to enclose the
references to the form controls with # so the query will understand it is a
date. This assumes the fields in the table are date data types.

Between "#" & Forms![FormName]![StartDate] & "#" And "#" &
Forms![FormName]![EndDate] & "#"

bobn3faw said:
My Access 2003 query with criteria to act onstart and end dates for a report:

I created Unbound Form with Unbound Start Date and EndDate. It calls a Macro
which calls a report.
I created Report which has Record Source to Query
I created a Query which has following Criteria:
Between [StartDate] And [EndDate]

Instead of bringing up the Form, it brings up two "Enter Value" windows. I
cannot get it to call the Form.

I have done this many times in prior versions of Access. Will apprecuate
suggestions as to what I may have missed.

(e-mail address removed)
 

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