Dates in a form for filtering Report query

J

Jan T.

I have a form "Period" with two text boxes. One for startDate
and one for EndDate. I want to use that form to limit the query
for my Report by the dates. However, when I refer to the
Form it does not seem to understand it is a date? I use the following
statement in my query:

SELECT Opphold.CheckIn
FROM Opphold
WHERE (((Opphold.CheckIn)<=[Forms]![Perioder].[txtStartDate]));

I also tried to convert it to a date like the following:
CDate(<=[Forms]![Perioder].[txtStartDate]))) but that did not work?

What should I do in order to the query to read the condition or dates from
my forms?

(The only thing I CAN get to work is if I make a function in vba that return
the value or date from the form and refering to the function in my Report
query:
Function startingDate(myStart as Date) as Date
startingDate = Forms("Period").txtStartDate
End Function)

Appreciate your answer.
Regards
Jan T.
 
F

fredg

I have a form "Period" with two text boxes. One for startDate
and one for EndDate. I want to use that form to limit the query
for my Report by the dates. However, when I refer to the
Form it does not seem to understand it is a date? I use the following
statement in my query:

SELECT Opphold.CheckIn
FROM Opphold
WHERE (((Opphold.CheckIn)<=[Forms]![Perioder].[txtStartDate]));

I also tried to convert it to a date like the following:
CDate(<=[Forms]![Perioder].[txtStartDate]))) but that did not work?

What should I do in order to the query to read the condition or dates from
my forms?

(The only thing I CAN get to work is if I make a function in vba that return
the value or date from the form and refering to the function in my Report
query:
Function startingDate(myStart as Date) as Date
startingDate = Forms("Period").txtStartDate
End Function)

Appreciate your answer.
Regards
Jan T.

You seem to have a discrepancy in the name of the form.
1) Your opening statement .... I have a form "Period"
2) Your Where clause .... <=[Forms]![Perioder].[txtStartDate]))
3) Your Function .... startingDate = Forms("Period").txtStartDate

Perioder is not the same as Period. If the name of the form is
actually "Period" the query will not be able to find the form nor the
date.

The correct Where clause syntax to return records between 2 dates
should be:
WHERE Opphold.CheckIn Between [Forms]![Period]![txtStartDate] AND
[Forms]![Period]![txtEndDate];

I would also suggest you make sure the 2 controls in the form have
their format property set to a valid US (mm/dd/yyyy) or ISO
(yyyy-mm-dd) date format.
Also, make sure the form is open when the query is run.
 
J

Jan T.

fredg said:
I have a form "Period" with two text boxes. One for startDate
and one for EndDate. I want to use that form to limit the query
for my Report by the dates. However, when I refer to the
Form it does not seem to understand it is a date? I use the following
statement in my query:

SELECT Opphold.CheckIn
FROM Opphold
WHERE (((Opphold.CheckIn)<=[Forms]![Perioder].[txtStartDate]));

I also tried to convert it to a date like the following:
CDate(<=[Forms]![Perioder].[txtStartDate]))) but that did not work?

What should I do in order to the query to read the condition or dates
from
my forms?

(The only thing I CAN get to work is if I make a function in vba that
return
the value or date from the form and refering to the function in my Report
query:
Function startingDate(myStart as Date) as Date
startingDate = Forms("Period").txtStartDate
End Function)

Appreciate your answer.
Regards
Jan T.

You seem to have a discrepancy in the name of the form.
1) Your opening statement .... I have a form "Period"
2) Your Where clause .... <=[Forms]![Perioder].[txtStartDate]))
3) Your Function .... startingDate = Forms("Period").txtStartDate

Perioder is not the same as Period. If the name of the form is
actually "Period" the query will not be able to find the form nor the
date.

The correct Where clause syntax to return records between 2 dates
should be:
WHERE Opphold.CheckIn Between [Forms]![Period]![txtStartDate] AND
[Forms]![Period]![txtEndDate];

I would also suggest you make sure the 2 controls in the form have
their format property set to a valid US (mm/dd/yyyy) or ISO
(yyyy-mm-dd) date format.
Also, make sure the form is open when the query is run.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Oobs Perioder was an writing error and now corrected. However, I still
can not understand that the form contains a date? I also tried different
formats like US m/d/yyyy or European dd.mm.yyyy but none of them
work. I am getting the parameter Input Box because I looks for a date?

Regards
Jan T.
 
J

Jan T.

Found out. It was because of a writing error it did not work. Did not see
that. :)
Thanx for your help. Jan T

Jan T. said:
fredg said:
I have a form "Period" with two text boxes. One for startDate
and one for EndDate. I want to use that form to limit the query
for my Report by the dates. However, when I refer to the
Form it does not seem to understand it is a date? I use the following
statement in my query:

SELECT Opphold.CheckIn
FROM Opphold
WHERE (((Opphold.CheckIn)<=[Forms]![Perioder].[txtStartDate]));

I also tried to convert it to a date like the following:
CDate(<=[Forms]![Perioder].[txtStartDate]))) but that did not work?

What should I do in order to the query to read the condition or dates
from
my forms?

(The only thing I CAN get to work is if I make a function in vba that
return
the value or date from the form and refering to the function in my
Report
query:
Function startingDate(myStart as Date) as Date
startingDate = Forms("Period").txtStartDate
End Function)

Appreciate your answer.
Regards
Jan T.

You seem to have a discrepancy in the name of the form.
1) Your opening statement .... I have a form "Period"
2) Your Where clause .... <=[Forms]![Perioder].[txtStartDate]))
3) Your Function .... startingDate = Forms("Period").txtStartDate

Perioder is not the same as Period. If the name of the form is
actually "Period" the query will not be able to find the form nor the
date.

The correct Where clause syntax to return records between 2 dates
should be:
WHERE Opphold.CheckIn Between [Forms]![Period]![txtStartDate] AND
[Forms]![Period]![txtEndDate];

I would also suggest you make sure the 2 controls in the form have
their format property set to a valid US (mm/dd/yyyy) or ISO
(yyyy-mm-dd) date format.
Also, make sure the form is open when the query is run.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Oobs Perioder was an writing error and now corrected. However, I still
can not understand that the form contains a date? I also tried different
formats like US m/d/yyyy or European dd.mm.yyyy but none of them
work. I am getting the parameter Input Box because I looks for a date?

Regards
Jan T.
 
D

De Jager

Jan T. said:
I have a form "Period" with two text boxes. One for startDate
and one for EndDate. I want to use that form to limit the query
for my Report by the dates. However, when I refer to the
Form it does not seem to understand it is a date? I use the following
statement in my query:

SELECT Opphold.CheckIn
FROM Opphold
WHERE (((Opphold.CheckIn)<=[Forms]![Perioder].[txtStartDate]));

I also tried to convert it to a date like the following:
CDate(<=[Forms]![Perioder].[txtStartDate]))) but that did not work?

What should I do in order to the query to read the condition or dates from
my forms?

(The only thing I CAN get to work is if I make a function in vba that
return
the value or date from the form and refering to the function in my Report
query:
Function startingDate(myStart as Date) as Date
startingDate = Forms("Period").txtStartDate
End Function)

Appreciate your answer.
Regards
Jan T.
 

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

Similar Threads

Date Range Query Problem 20
Report help 8
Report Help 1
Parameter Query 2
Reference controls on a dialogue form as the parameters 1
Date Range on Report 6
Running Update Query in VBA fails 5
Query dates 1

Top