From: Lars Brownies on 16 Feb 2010 02:07 I have a combobox in which the afterupdate triggers a msgbox. In only want this msgbox to show if the combobox value has really changed. Sometimes a user selects a value for the combobox that is already the value of that combobox. Is there a way that I can check if the user has really chosen a new value? I can think of using a global var which the old value get filled in the beforeupdate and checked in the afterupdate. But maybe there is a more elegant way? Thanks, Lars
From: Allen Browne on 16 Feb 2010 03:05 If the combo is bound to a field in your table, compare its Value to its OldValue, e.g.: With Me.Combo1 If (.Value = .OldValue) OR (IsNull(.Value) = IsNull(.OldValue)) Then 'Nothing changed Else 'It did change. End If End With If it's unbound, you will need to use a module-level variable (i.e. declared in the General Declarations section of the module of the form that contains the combo.) -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Lars Brownies" <Lars(a)Browniew.com> wrote in message news:hldg84$l54$1(a)textnews.wanadoo.nl... > I have a combobox in which the afterupdate triggers a msgbox. In only want > this msgbox to show if the combobox value has really changed. Sometimes a > user selects a value for the combobox that is already the value of that > combobox. Is there a way that I can check if the user has really chosen a > new value? I can think of using a global var which the old value get > filled in the beforeupdate and checked in the afterupdate. But maybe there > is a more elegant way? > > Thanks, > > Lars
From: Lars Brownies on 16 Feb 2010 03:34 Excellent! Thanks. Lars "Allen Browne" <AllenBrowne(a)SeeSig.Invalid> schreef in bericht news:e13zH7trKHA.6004(a)TK2MSFTNGP04.phx.gbl... > If the combo is bound to a field in your table, compare its Value to its > OldValue, e.g.: > > With Me.Combo1 > If (.Value = .OldValue) OR (IsNull(.Value) = IsNull(.OldValue)) > Then > 'Nothing changed > Else > 'It did change. > End If > End With > > If it's unbound, you will need to use a module-level variable (i.e. > declared in the General Declarations section of the module of the form > that contains the combo.) > > -- > Allen Browne - Microsoft MVP. Perth, Western Australia > Tips for Access users - http://allenbrowne.com/tips.html > Reply to group, rather than allenbrowne at mvps dot org. > > > "Lars Brownies" <Lars(a)Browniew.com> wrote in message > news:hldg84$l54$1(a)textnews.wanadoo.nl... >> I have a combobox in which the afterupdate triggers a msgbox. In only >> want this msgbox to show if the combobox value has really changed. >> Sometimes a user selects a value for the combobox that is already the >> value of that combobox. Is there a way that I can check if the user has >> really chosen a new value? I can think of using a global var which the >> old value get filled in the beforeupdate and checked in the afterupdate. >> But maybe there is a more elegant way? >> >> Thanks, >> >> Lars >
From: David W. Fenton on 16 Feb 2010 15:28 "Allen Browne" <AllenBrowne(a)SeeSig.Invalid> wrote in news:e13zH7trKHA.6004(a)TK2MSFTNGP04.phx.gbl: > If (.Value = .OldValue) OR (IsNull(.Value) = > IsNull(.OldValue)) Then Is there really any advantage in shortcircuiting that? Why not just run the 2nd test? It's not like you're doing it in a loop where a tiny performance difference could eventually add up to something significant. -- David W. Fenton http://www.dfenton.com/ usenet at dfenton dot com http://www.dfenton.com/DFA/
From: Allen Browne on 16 Feb 2010 19:32
Not sure what 'shortcircuiting' refers to, David. The cases where it hasn't changed would be identified as: a) value is the same as it was OR b) value was null and still is null. -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "David W. Fenton" <XXXusenet(a)dfenton.com.invalid> wrote in message news:Xns9D219D5C1B55Df99a49ed1d0c49c5bbb2(a)74.209.136.89... > "Allen Browne" <AllenBrowne(a)SeeSig.Invalid> wrote in > news:e13zH7trKHA.6004(a)TK2MSFTNGP04.phx.gbl: > >> If (.Value = .OldValue) OR (IsNull(.Value) = >> IsNull(.OldValue)) Then > > Is there really any advantage in shortcircuiting that? Why not just > run the 2nd test? It's not like you're doing it in a loop where a > tiny performance difference could eventually add up to something > significant. > > -- > David W. Fenton http://www.dfenton.com/ > usenet at dfenton dot com http://www.dfenton.com/DFA/ |