Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional date filter Access 2007 form? 1

Status
Not open for further replies.

dpelizzari

IS-IT--Management
Jul 23, 2010
17
0
0
US
I have built a form that filters data between two dates (start date, end date) as well as another criteria (site code). If the user puts in the start and end date, they can retrieve all records in that range, however, if they leave the date fields blank, they get no records returned. What I would like it to do is if either date field is null, to pull all records either before or after the dates respectively.
In a nutshell:
If start date is null, and end date is not null, select all records before end date and apply site code filter if necessary.
If start date is not null and end date is null, select all records after start date and apply site code filter if necessary.

Here is my filter code currently:

Code:
WHERE ((([dbo_ISD SACD1].epend_dt)>=[Forms]![Parameters]![StartDate] And ([dbo_ISD SACD1].epend_dt)<=[Forms]![Parameters]![EndDate]) AND (([dbo_ISD SACD1].rSite) Like Nz([Forms]![Parameters]![Site Code],"*")));

Note, I am using a form to capture the data before opening the form that presents the data.
 
Code:
WHERE ([dbo_ISD SACD1].epend_dt>=[Forms]![Parameters]![StartDate] OR [Forms]![Parameters]![StartDate] IS NULL)
AND ([dbo_ISD SACD1].epend_dt<=[Forms]![Parameters]![EndDate] OR [Forms]![Parameters]![EndDate] IS NULL)
AND [dbo_ISD SACD1].rSite Like Nz([Forms]![Parameters]![Site Code],"*")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks, PHV! quick, easy, and I should have seen that. You deserve the star I gave you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top