Full Version: Query date range w/ blank field for one day
UtterAccess Discussion Forums > Microsoft® Access > Access Queries
emanuelme
I am pretty new to access and need some help with a date range query:

I have created the query such that a user can enter a start day and end day on a form and get a respose for the days selected. I want the user to be able to leave the end day field blank if they only want to search for one specific date. I.E. if the only want to see todays records as opposed to the past two weeks.

The following is my code for the date range query:

SELECT tbl_non_training_days.*, tbl_non_training_days.Date, tbl_non_training_days.Title, tbl_non_training_days.Comments
FROM tbl_non_training_days
WHERE (((tbl_non_training_days.Date) Between [forms]![frm_training_days]![start_date] And [forms]![frm_training_days]![end_date]));

I read about the NZ function as well as the IIf and ISNull but dont understand them. I would greatly appreciate some help.

-Emanuel
balaji
Try this:

SELECT tbl_non_training_days.*, tbl_non_training_days.Date, tbl_non_training_days.Title, tbl_non_training_days.Comments
FROM tbl_non_training_days
WHERE (((tbl_non_training_days.Date) Between [forms]![frm_training_days]![start_date] And nz([forms]![frm_training_days]![end_date],[forms]![frm_training_days]![start_dat
e])));
Jack Cowley
I would use code in the form to automatically fill in the EndDate control with the value entered into the StartDate control. The user can then leave the date alone or change it if they want a different EndDate.... Code like this in the After Update event of the StartDate control should do the trick:

Me.end_date = Me.start_date

hth,
Jack
emanuelme
Thanks for the help...... I used the query code....couldnt figure out the coding on the after udate....
Jack Cowley
You are welcome and I am glad that you were able to get the query code to do the trick for you...

Jack
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.