Validate value in combobox based on before/after update

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mcupito
    Contributor
    • Aug 2013
    • 294

    Validate value in combobox based on before/after update

    I have a combobox on a form where users can select number of payouts. The choices are 3, 5 and 10.

    I am trying to implement a validation rule that checks to see if the user tries to change the number of payouts to a number less than what was in the combobox prior to their change. If so, do not allow the change to be saved.

    Example:

    The current number of payouts is: 10
    *User tries to change to 5*
    Validation Text: You've made an invalid election.
    *System does not allow them to save that change*

    I know we need to capture the value in the combobox before update, and also use it in the after update, to compare each selection, yet I'm not sure how to store the value of the before update selection.

    Anyone have any ideas? Thanks
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You can do it all in the before update, check the old value against the value that it will update to. Both are available to you in that event. The OldValue property will hold the original value.

    Comment

    • mcupito
      Contributor
      • Aug 2013
      • 294

      #3
      Great - Thanks, Rabbit!

      Although what you said has helped me. I am still left with one question.

      If I do:
      Code:
      If Me.PayoutCbx.OldValue > Me.PayoutCbx.Value Then
          MsgBox ("Number Of Payouts cannot be decreased.")
      End If
      How do I prevent the user's entry to over-ride the oldvalue? I tried .SetFocus and Me.PayoutCbx = Me.PayoutCbx.Ol dValue, and neither worked.

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        Code:
        Cancel = true
        Me!ControlNameHere.Undo
        (note, the undo is valid for bound controls)

        Please see the section for the before update even in the MS Developer's materials: Form.BeforeUpda te Event (Access) Office 2010 There are a few more code snipits for you to look at in the reference too (^_^)

        Comment

        • mcupito
          Contributor
          • Aug 2013
          • 294

          #5
          Great - Thanks, zmbd! Works beautifully.
          Last edited by zmbd; Jan 28 '14, 09:14 PM. Reason: [z{You're Welcome. I rest BstAnswr to Rabbit because that was the first point, I just expanded (^_^)]]

          Comment

          Working...