none
How do I check value of control before and after update? RRS feed

  • Question

  • I am trying to fire some code when the value of a control(ComboBox in this case) goes from a specific value, to another specific value.

    I'm having trouble find a property that shows me the value in the control before and after so that I can compare them.

    I suppose I could store the old value in a variable on the BeforeUpdate Event myself, then hold it in a Private variable at the top of the form code module so I could compare it to the value of the control during the AfterUpdate Event. But this somehow feels wrong to me, and a mess later when I have to remember why I did that. Am I over thinking this? The combo box has a number of different values the user can select. When it goes from value XYZ to value ABC I want to know so I can fire some code. But I may need different code to fire if it goes from XYZ to DEF, for example. Thats why I need the before and after values to compare them.

    Thanks for the advice.
    Friday, January 22, 2016 5:11 PM

Answers

  • A bound control's OldValue property holds the value the control had when the record was initially loaded on the form, or its value after the record has been saved.  If your combo box is bound, then the OldValue property may be what you want.

    If your combo box is not bound, then it's harder, because the OldValue property of an unbound control is always the same as its Value property.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    • Marked as answer by HTHP Friday, January 22, 2016 5:52 PM
    Friday, January 22, 2016 5:20 PM

All replies

  • A bound control's OldValue property holds the value the control had when the record was initially loaded on the form, or its value after the record has been saved.  If your combo box is bound, then the OldValue property may be what you want.

    If your combo box is not bound, then it's harder, because the OldValue property of an unbound control is always the same as its Value property.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    • Marked as answer by HTHP Friday, January 22, 2016 5:52 PM
    Friday, January 22, 2016 5:20 PM
  • Thank you that should make things easier. Because this control is bound, I will not worry about how to handle an unbound instance of this problem until I come across some spare time or if it becomes critical. I was searching here: https://msdn.microsoft.com/en-us/en-us/library/office/ff822556.aspx and should have seen this.
    Friday, January 22, 2016 5:50 PM