Change updated field behavior

mafhobb

Registered User.
Local time
Yesterday, 21:53
Joined
Feb 28, 2006
Messages
1,250
Hi all,

I have a combo box field that has two options: YES or NO.

The default is NO.

I have some code that sends an automatic e-mail to a group of people when the combo box is set to YES (after update event), which works really well. However, if anyone clicks on the box while it says YES and simply exits it, Access assumes that the box has been updated, it finds the YES and then it sends the same e-mail again.

To stop this I need code that checks the original entry and compares it to the new entry and if they are the same (two YES) then, do nothing. I imagine that a before update event needs to be used, but I am not sure how to do it.

Can someone provide a small example?

Thanks

Mafhobb
 
i'm not sure off-hand if this works for combo boxes but have a look at the Old Value property. you can do a comparison with that. Old Value represents the original, saved value. you can compare the current entry with the value.

if old value doesn't work with combos (i think it does), you can store the initial value in a module-level variable as soon as you get to a record (On Current), or in a hidden text box on the form.
 
Any idea what the code would be to look up the oldvalue?
 
Any idea what the code would be to look up the oldvalue?
Code:
If Me.YourComboBoxName.OldValue <> Me.YourComboBoxName Then
  ...then do your code to send out here
End If
 
I'll give it a try right away.

Thanks

mafhobb
 
i am sure bob has it right - but you may actually need to set a control flag in the beforeupdate event, and test it in the afterupdate. (you cant test for the oldvalue in the afterupodate eent, because it gets changed by the save commit)

if your email proc depends on values in the record, the values wont be updated until the update completes, and therefore firing the email from the before update event may not report the correct data.
 
probably needs to be snagged in the Before Update event.
 
It works fine as is. The e-mail is only sent in the afterupdate event after the if, checking for the values in the box.

Thanks for the help!

mafhobb
 

Users who are viewing this thread

Back
Top Bottom