Open Report Conditions

G

Guest

DS,

You could base your reports on a query that uses the
between FORMS!yourform!TxtStartDate and FORMS!yourform!TxtEndDate
as its criteria. Then when the user selects the report they want, the
query will handle the restriction and your code can just open the report.

hth

Vanya
 
D

DS

I have a listbox where I select a report to open. This value then goes into
a textbox. I also have a start and end date textbox on my form which tels
me from what dates I need to run the report. My question is how do I do
this from a command button?

DoCmd.OpenReport"Me.TextBoxReportName",,,,StartDate=Me.TxtStartDate and
EndDate = Me.TextEndDate"

This doesn't seem to work, any help is appreciated.
Thanks
DS
 
L

Larry Linson

DS said:
I have a listbox where I select a report to open. This value then goes
into a textbox. I also have a start and end date textbox on my form which
tels me from what dates I need to run the report. My question is how do I
do this from a command button?

DoCmd.OpenReport"Me.TextBoxReportName",,,,StartDate=Me.TxtStartDate and
EndDate = Me.TextEndDate"

You want to report only on the "whatevers" that have both the exact start
date and exact end date? That's what it seems you are trying...

Change your WhereCondition argument to

"[StartDate] = #" & Me.txtStartDate & "# AND [EndDate] = #" & Me.txtEndDate
& "#"

and see if that doesn't work better. If you read carefully, the WHERE
condition argument is a text string, and your syntax doesn't generate a text
string.

However, I rarely want to be that specific on dates when reporting, so
usually I will be using a WhereCondition argument, or WHERE clause that
specifies a date BETWEEN two dates.

Larry Linson
Microsoft Access MVP
 
L

Larry Linson

Oops, sorry I missed that... that argument shouldn't be in quotes. You are
trying to open a report that has the exact name "Me.TextBoxReportName", not
getting the value from TextBoxReportName... remove those quotes, and you'll
get the value from the text box.

Larry Linson
Microsoft Access MVP

DS said:
OK I think the date thing seems to be right, I'm doing between
dates...also I still can't get the report to open based on the report name
thats in the textbox......I think the real problem lies there.
Thanks
DS
Larry Linson said:
DS said:
I have a listbox where I select a report to open. This value then goes
into a textbox. I also have a start and end date textbox on my form
which tels me from what dates I need to run the report. My question is
how do I do this from a command button?

DoCmd.OpenReport"Me.TextBoxReportName",,,,StartDate=Me.TxtStartDate and
EndDate = Me.TextEndDate"

You want to report only on the "whatevers" that have both the exact start
date and exact end date? That's what it seems you are trying...

Change your WhereCondition argument to

"[StartDate] = #" & Me.txtStartDate & "# AND [EndDate] = #" &
Me.txtEndDate & "#"

and see if that doesn't work better. If you read carefully, the WHERE
condition argument is a text string, and your syntax doesn't generate a
text string.

However, I rarely want to be that specific on dates when reporting, so
usually I will be using a WhereCondition argument, or WHERE clause that
specifies a date BETWEEN two dates.

Larry Linson
Microsoft Access MVP
 
D

DS

Thanks Ivan seems simple enough!
DS
Ivan Grozney said:
DS,

You could base your reports on a query that uses the
between FORMS!yourform!TxtStartDate and FORMS!yourform!TxtEndDate
as its criteria. Then when the user selects the report they want, the
query will handle the restriction and your code can just open the report.

hth

Vanya
 
D

DS

OK I think the date thing seems to be right, I'm doing between dates...also
I still can't get the report to open based on the report name thats in the
textbox......I think the real problem lies there.
Thanks
DS
Larry Linson said:
DS said:
I have a listbox where I select a report to open. This value then goes
into a textbox. I also have a start and end date textbox on my form which
tels me from what dates I need to run the report. My question is how do I
do this from a command button?

DoCmd.OpenReport"Me.TextBoxReportName",,,,StartDate=Me.TxtStartDate and
EndDate = Me.TextEndDate"

You want to report only on the "whatevers" that have both the exact start
date and exact end date? That's what it seems you are trying...

Change your WhereCondition argument to

"[StartDate] = #" & Me.txtStartDate & "# AND [EndDate] = #" &
Me.txtEndDate & "#"

and see if that doesn't work better. If you read carefully, the WHERE
condition argument is a text string, and your syntax doesn't generate a
text string.

However, I rarely want to be that specific on dates when reporting, so
usually I will be using a WhereCondition argument, or WHERE clause that
specifies a date BETWEEN two dates.

Larry Linson
Microsoft Access MVP
 
D

DS

Thanks, That did the trick
DS
Larry Linson said:
Oops, sorry I missed that... that argument shouldn't be in quotes. You are
trying to open a report that has the exact name "Me.TextBoxReportName",
not getting the value from TextBoxReportName... remove those quotes, and
you'll get the value from the text box.

Larry Linson
Microsoft Access MVP

DS said:
OK I think the date thing seems to be right, I'm doing between
dates...also I still can't get the report to open based on the report
name thats in the textbox......I think the real problem lies there.
Thanks
DS
Larry Linson said:
I have a listbox where I select a report to open. This value then goes
into a textbox. I also have a start and end date textbox on my form
which tels me from what dates I need to run the report. My question is
how do I do this from a command button?

DoCmd.OpenReport"Me.TextBoxReportName",,,,StartDate=Me.TxtStartDate and
EndDate = Me.TextEndDate"

You want to report only on the "whatevers" that have both the exact
start date and exact end date? That's what it seems you are trying...

Change your WhereCondition argument to

"[StartDate] = #" & Me.txtStartDate & "# AND [EndDate] = #" &
Me.txtEndDate & "#"

and see if that doesn't work better. If you read carefully, the WHERE
condition argument is a text string, and your syntax doesn't generate a
text string.

However, I rarely want to be that specific on dates when reporting, so
usually I will be using a WhereCondition argument, or WHERE clause that
specifies a date BETWEEN two dates.

Larry Linson
Microsoft Access MVP
 

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


Top