Comparison with OldValue

  • Thread starter Thread starter Tim
  • Start date Start date
T

Tim

I have a form in my database with two fields which can be
completed by the user. One is called status and is a
combo box. I want to trigger some code only if the stsus
box has been updated and so am trying to use the OldValue
property with the form AfterUpdate event, as follows:

if status <> status.OldValue Then
Run my code

This does not seem to work. Has anyone used this and can
give me some tips?
 
Assuming that Status is a bound control (so it does have an OldValue
property), the problem may be with Null values. The comparison:
If Status <> Status.OldValue ...
is only true if there was a value in Status (not Null), and there still is a
value in Status (not Null), and the value has changed.

The simplest way to code around that is:
If Status = Status.OldValue Then
'do nothing
Else
'run your code
End If
That may look strange, but the "Else" fires for all the conditions except
where the value is unchanged.

This issue is one of 6 discussed in:
Common errors with Null
at:
http://allenbrowne.com/casu-12.html

Post back if that is not the cause of the problem.
 
I tried to test this generating two different message
boxes depending on whether the status had changed or not,
but it always seemed to produce the "no change" response.

I think it was because I was running it as an AfterUpdate
event? I changed it to BeforeUpdate and it seems to work
OK.

Thanks
 
Re my last post, the BeforeUpdate option generates a write
conflict warning as part of my code updates the record in
question and setting the warnings to false does not
prevent the message appearing. Any ideas?
 
Well, it does make sense that if you write the same data, and then try to
update afterwards, you will get a write conflict.

Requires a change in your strategy.
 
Back
Top