Validate Date field

Posted on 2011-04-24
Last Modified: 2013-11-28
Hello experts ,
i have a problem with date validation.What i want to do is to validate the date field in my form and disable access error messages at the same time.In face i have implemeneted the validation rule for the date field and i have configured input mask and validation text. Although if i enter a wrong date in the format dd/mm/yyyy , for example :12/13/2011 (which is wrong) i get :
"The value you entered isn't valid for this field" .How can i prevent this from happening and display only my custom text entered in the validation text property ?
(I forgot to mention that i have user error handling for this and it didn't work.Is there any other way to achieve this ?)

Waiting for your replies!
Question by:stathisx
    LVL 31

    Expert Comment

    Try this code on the BeforeUpdate event to check that a valid date has been entered into a control.  There may not be a need for a validation rule.

    In my experience, it is best to not have an input mask for dates, but just use the Format property to display the date in the desired format, no matter how it was entered.

    If IsDate(Me![txtFromDate].Value) = True Then
       Cancel = False
       'Your error message
    End If

    Open in new window

    LVL 44

    Expert Comment

    Post the code from the function in which you are having difficulty.
    LVL 44

    Expert Comment

    Make that Sub/Function
    LVL 23

    Accepted Solution

    hi stathisx,
    - if you plan to customized most of the errors that might hit on your forms, then you might want to look into the following article. a "The value you entered isn't valid for this field" is not the only error related to date. therefore you need to capture the error number, then specify a customized error for that error number, be it value isn't valid, invalid date format, and so on.
    LVL 1

    Author Comment

    in the form onerror event i trapped the error codes (2113 and 2116) and changed the response argument to acdataerrcontinue and it worked .
    thank you all for the replies!

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
    Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now