Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Date Validation Rules for Access?

I am trying to create a validation rule for Access that would try and use other fields to limit entries. So if a field2 is 'yes' then I want my date field to be restricted to jan-may and if field2 is 'no' then my date field to be restricted from june-dec. Is this possible?

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    Yes if the data is being entered on a form.

    Try this

    Let's assume your yes/no field is bound to a checkbox called chkD, and the date in entered into a text box named txtDate:

    then for the After Update event for that check box, put

    Private Sub chkD_AfterUpdate()

      If (chkD = True) Then

        txtDate.ValidationRule = "Month(txtDate) between 1 and 5"

        txtDate.ValidationText = "your own error message 1"

      Else

        txtDate.ValidationRule = "Month(txtDate) between 6 and 12"

        txtDate.ValidationText = "your own error message 2"

      End If

    End Sub

    The "= True" is redundant, but makes the code a little more readable

    When you enter a (wrong) date into the text box, the error message containing your validation text will appear when you try to move the focus to another control on the form

    Hope that helps

  • 5 years ago

    ask a lawyer

Still have questions? Get your answers by asking now.