Using field in a form to set parameters for a query

D

DM - NPS

I have a form that lets the user pick a report, set the date (StartDate &
EndDate) and select a specific area (AreaKey). The idea being the query the
report is based on will use the dates and area selected by the user in the
query so the report is only for the parameters specified.

In the date field of the query I have:
=[forms].[frmReportMenu].[StartDate] And <=[forms].[frmReportMenu].[EndDate]

In the Site_ID field I have: [forms].[frmReportMenu].[AreaKey]

This works but the user must enter a date (which is fine) and an area.
Where I run into problems is when the user wants to run the report for all
sites. If they leave the AreaKey field empty the report returns no values
when it should return the data for all sites.

Any Ideas?
 
G

ghetto_banjo

The Nz function might work here. Try this criteria for your Site_ID

Like Nz([Forms]![frmReportMenu].[AreaKey], "*")
 
D

DM - NPS

Seems like it should have worked but I still come up with a blank report
unless I fill in all the parameters
 
D

Duane Hookom

WHERE Site_ID = [forms].[frmReportMenu].[AreaKey] OR
[forms].[frmReportMenu].[AreaKey] Is Null

I generally don't put any dynamic criteria in record source queries. I
prefer building a where condition to use in the DoCmd.OpenReport method.

--
Duane Hookom
Microsoft Access MVP


DM - NPS said:
I have a form that lets the user pick a report, set the date (StartDate &
EndDate) and select a specific area (AreaKey). The idea being the query the
report is based on will use the dates and area selected by the user in the
query so the report is only for the parameters specified.

In the date field of the query I have:
=[forms].[frmReportMenu].[StartDate] And <=[forms].[frmReportMenu].[EndDate]

In the Site_ID field I have: [forms].[frmReportMenu].[AreaKey]

This works but the user must enter a date (which is fine) and an area.
Where I run into problems is when the user wants to run the report for all
sites. If they leave the AreaKey field empty the report returns no values
when it should return the data for all sites.

Any Ideas?
 

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