Link to home
Start Free TrialLog in
Avatar of jaguar5554
jaguar5554Flag for United States of America

asked on

Is there a way to apply an input mask to a query parameter?

Is there a way to force the end user to enter a date parameter in a certain format when prompted via the query (e.g. 1/1/2014 (4-digit year)). I have users that accidentally enter 1/1/201 (forgetting the last digit of the year), and because 1/1/201 is a valid date, the query continues to run returning unexpected data results. Any thoughts? (PS: passing the date through a form is not an option for this project). Much thanks in advance!
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

No. The best you can do is to create a small form for the user to enter the search criteria, then open the query using these.

/gustav
One idea, is to check for the last 4 digits, if less than 4, input a false date. The field to check for is [Start Date], the parameter is stdt. The false date is 1/1/1900.

SELECT ID, [Start Date]
FROM tbl
WHERE [start date]=IIF( Len(Right(stdt,LEN(stdt)-InStr(4,stdt,"/")))=4, stdt, #1/1/1900#);

Open in new window

Avatar of jaguar5554

ASKER

I had actually come up with a very similar solution -- using an IIF statement to check the length of the inputted date. Thank you!  Unfortunately, the query is still returning unexpected results. I'm thinking about using the IIF statement in the query, but perhaps adding a message box or something that alerts the user when running the report that the date range is an impossible one (e.g. more than 5 years, etc.). But I am still open to any other ideas.
You can't win that battle. The tiny parameter box is for people like you, not end users.

Using a form, you can have proper error handling and communication with the user.

/gustav
ASKER CERTIFIED SOLUTION
Avatar of Hamed Nasr
Hamed Nasr
Flag of Oman image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Very nice. Unfortunately, I can't use the WHERE clause. The date is user-defined and included in the dataset. To be more specific, the user is prompted for a date, and what is entered by the end user is then included in each record that is returned by the query. That date is then used later in other queries and reporting. I recognize that this issue could be better resolved using a form to pass the date to the query but that is not an option at this time. If there was only a way to apply an input mask on the query parameter, or force the user to re-enter the date if it's not a 4-digit year.
If that was the case, you could win the battle. But, as said, you can't.
This is a well-known issue, and the proved workaround is well-known too.

/gustav
As others have said, query parameters just aren't meant for end users.  They're horrible.  I don't understand why a form isn't an option - it's the right way to do it, and would give you all the control you need.  It's like saying you're having trouble cutting tomatoes with a spoon, but a knife isn't an option.

If you do decide that a form is a possibility, then have a look at some examples I've posted of how to use forms to build Where clauses for reports.  It's a free download called Report Selection Techniques at http://www.JStreetTech.com/downloads.

Cheers,
Armen Stein, Access MVP
J Street Technology
Great analogy! LOL However, I was asked to assist on a co-worker's project and my recommendation to pass the date through a form was declined.

Thanks everyone for your feedback. I will try to adapt the IIF statement as provided by hnasr, as well as check out the downloads site as suggested by Armen -- both helpful.
Welcome!