Question : Adding user-input date range to query in MS Access

Hi,

I’ve searched and found broadly similar questions to this, but none close enough for me to figure it out (rusty on Access these days).

I have an MS Access database with a form in which the user selects a file through a dialog box and then clicks an ‘Export’ button. When they press the button qryABC is run and its results are output to the file selected in the dialog box. All working perfectly there.

I’d like to change it so the user can enter a StartDate and EndDate in the form, and then when they click the button, qryABC only returns results within this date range (i.e. the dates are added as a clause to qryABC).

First off, I’m unsure how to add textfields to the form to allow the user enter dates – would have thought there’d be a built-in calendar module by now, but failing that would a free-textfield be best? Am not sure how to add a free-textfield (have only managed to do bound textfields).

Second to that, how do I add the dates selected by the user as a clause in qryABC, assuming the form name is frmXYZ, the query is qryABC, and the textfields should be named StartDate and EndDate?

I’m in Ireland, so dates should be dd/MM/YYYY format, though when I look in the SQL View the dates are shown as #MM/dd/YYYY#. What would be the best way to validate the user-selected dates to avoid errors?

Many thanks.

Answer : Adding user-input date range to query in MS Access

Add an an activeX control called Microsoft Date & Time Picker.  In design mode, click more controls, scroll down and see if you have the control.  If not download this reference from microsoft.  Then register it.
MSCOMCT2.OCX
http://support.microsoft.com/kb/297381

It's a calendar that when you hit the arrow, the calendar pops up.  It acts like a txtbox.  You can format it anyway you want
Then reference the DatePicker box to your query

[Forms][YourForm][DatePicker1] <<<<<<<<<<<<<[Forms][YourForm][DatePicker2]<<<<<<<<<<<<< Date

net
Random Solutions  
 
programming4us programming4us