Share via

Validation Rules in Combo Box

Anonymous
2019-02-07T17:42:04+00:00

I have a combo box that includes a date. I have two buttons next to the combo box that will raise/lower the date by one year.

I have set this validation rule for the combo box: ">=#1/1/2012#"

However, I only get an alert about validation is I MANUALLY enter a date under 2012. If I click on the button to lower the date, I do not get the alert. How do I get the alert after pressing the button?

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Duane Hookom 26,825 Reputation points Volunteer Moderator
2019-02-08T03:33:46+00:00

You should be able to use something like:

Private Sub btnStartUp_Click()

Dim DateA As Date

DateA = DateAdd("yyyy", 1, Me.txtDateStart)

If DateA >=#1/1/2012# Then

MsgBox "Date to high"

Else

Me.txtDateStart = DateA

End If

End Sub

Was this answer helpful?

2 people found this answer helpful.
0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Anonymous
    2019-02-08T14:34:34+00:00

    Thank you dhookom. That worked

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2019-02-07T18:39:22+00:00

    The button code is posted below.

    Private Sub btnStartUp_Click()

    Dim DateA As Date

    DateA = DateAdd("yyyy", 1, Me.txtDateStart)

    Me.txtDateStart = DateA

    End Sub

    Private Sub btnStartDown_Click()

    Dim DateB As Date

    DateB = DateAdd("yyyy", -1, Me.txtDateStart)

    Me.txtDateStart = DateB

    Me.txtDateStart.ValidationRule = True

    End Sub

    My form allows users to enter a date. Then users will click a button that will open a query. The query runs based on the parameters of the set date.

    Was this answer helpful?

    0 comments No comments
  3. Duane Hookom 26,825 Reputation points Volunteer Moderator
    2019-02-07T17:55:20+00:00

    I assume your buttons have some code that sets the value. Add some validation in the click event of the buttons.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2019-02-07T17:50:30+00:00

    Please post the button code that lowers the date.

    Note that a Validation Rule usually applies to a field value stored in a Table; a Combo Box is not data, it's a TOOL for entering data. What's the context? Are you using this as a Lookup Field in a Table, or is the combo box on a Form?

    Was this answer helpful?

    0 comments No comments