Compare opening and closing values

M

Mike Collard

I have an unbound text box that gets populated with a
value which the user can then overtype. I want to be able
to trigger an event if the new value is different from the
old value. I don't think the On Change event will work
because that just detects if a value has been entered not
if it is different from the opening value.

So I need a method to compare the before and after values.
So far I have tried assigning the opening value to a
variable in the On Got Focus event and then comparing the
After Update value with this variable but Access doesn't
seem to recognise the variable name in the After Update
event so the action fails. Is it something to do with
Private and Public variables and their scope?

Grateful for help
 
A

Al Campagna

Mike,
My method for accomplishing this may not be "elegant", but it works...
and it's much easier to "bug" shoot. Let's call the field we'll be
monitoring [MyValue].
I place an unbound text control on the form (call it OldMyValue)
On the OnCurrent for the form, I set OldMyValue equal to the previously
entered MyValue.
Using the AfterUpdate event of My Value, I warn the user (Msgbox with
OK/Cancel) that they have changed MyValue.
If the user clicks Cancel, I copy the OldMyValue into MyValue and exit
the sub.
If the user clicks OK, I let the change to MyValue stand, and copy that
new value to OldValue... in case another change comes along.

It's basically the same as you are doing with a "variable", but using a
text control will allow you to watch the process as it happens. Once the
process has been coded and everything is working the way you want, you can
switch to a variable, but that's your choice.

Of course, you don't want the "I'm changing" warning on entering MyValue
on a NEW record, so include some "null" checking before firing off the
MyValue AfterUpdate code.
 
P

PC Datasheet

Mike ,

Put the following code in the BeforeUpdate event of the textbox:

If Me!TextboxName <> Me!TextboxName.OldValue Then
<<take the action you want to take>>
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top