Prompt user for query date range

Sade

Board Regular
Joined
Nov 29, 2004
Messages
145
Hello all. I an trying to write what should be a simple query to pull data within a date range specified by the user. This should be easy enough with the bracketed prompt in the criteria.

However, the query uses the "DateSerial" function to change the format of the field to date formatted instead of text. During my filter tests, just typing in a filter of "05/01/2011" does not work. I have to manually put in the number signs to signify a date: "#05/01/2011#". Usually this happens automatically, but I guess Access doesn't recognize the DateSerial format until after the query runs.

So, is there a way to prompt the user for date input and have Access put the "#" in automatically? I suppose I could do two queries so that Access would recognize the field as a date, but I'm looking for efficiency here.

Thanx
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
If I understand what you are wanting correctly, simply creating a form with two text boxes to choose a date range should suffice. For each text box, set the Format property to Short Date (or long date if you prefer). Make sure, "Show Date Picker" is set to "For Dates" or Always if that is an option.

This forces the user to enter a valid date which Access will recognize correctly. You will need to change the formula in your query to something like:
Code:
>=[Forms]![yourFormNameHere]![txtBegDate] And <=[Forms]![YourFormNameHere]![txtEndDate]
for whatever field the date is held. Also, change txtBegDate and txtEndDate to names of your text boxes on your form.

Then add a command button to run the query, and you should be set. Make sure that the query is run before the form closes, or else you will hit an error.
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top