By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,654 Members | 1,811 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,654 IT Pros & Developers. It's quick & easy.

Validate value in combobox based on before/after update

100+
P: 294
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
Jan 27 '14 #1

✓ answered by Rabbit

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.

Share this Question
Share on Google+
4 Replies


Rabbit
Expert Mod 10K+
P: 12,365
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.
Jan 27 '14 #2

100+
P: 294
Great - Thanks, Rabbit!

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

If I do:
Expand|Select|Wrap|Line Numbers
  1. If Me.PayoutCbx.OldValue > Me.PayoutCbx.Value Then
  2.     MsgBox ("Number Of Payouts cannot be decreased.")
  3. End If
How do I prevent the user's entry to over-ride the oldvalue? I tried .SetFocus and Me.PayoutCbx = Me.PayoutCbx.OldValue, and neither worked.
Jan 27 '14 #3

zmbd
Expert Mod 5K+
P: 5,397
Expand|Select|Wrap|Line Numbers
  1. Cancel = true
  2. 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.BeforeUpdate Event (Access) Office 2010 There are a few more code snipits for you to look at in the reference too (^_^)
Jan 28 '14 #4

100+
P: 294
Great - Thanks, zmbd! Works beautifully.
Jan 28 '14 #5

Post your reply

Sign in to post your reply or Sign up for a free account.