Apologies if Dup - Compare old and new values

  • Thread starter Thread starter Mike Collard
  • Start date Start date
M

Mike Collard

Apologies if this note is a duplicate but I have posted it
before and it was not displayed.

I have a form with an unbound text box that is populated
with a value by a procedure. If the user overtypes the
value in the text box with a new value I want this to
trigger an event.

The On Change event does not work because it only detects
if an entry is made, not if the entry value differs from
the original value, and although the user shouldn't
overtype with the same value it's possible they could get
focus on the control in error. So I need some code to
record the opening value of the control so that it can be
compared with the After Update value.

I have tried assigning the opening value to a variable
with the On Got Focus event and then referring to the
variable in the After Update event but it is not
recognised. I suspect it is something to do with the
scope of the variable i.e. how do I use the value of a
variable created in one procedure in another?

Any ideas/solutions appreciated.

Mike Collard
 
You're guess is probably correct. You need a form level variable. "Dim" the variable in
the Declarations section of the form's code module (the area where it say "Option Compare
Database" and, hopefully, "Option Explicit."
 
Mike,

Instead of trying to save the value in a module variable,
you could create another unbound text box on your form
and set its visibility to no. It will act as a hidden
value holder.

As the the focus moves to a control, the events that
occur are:

Enter => GotFocus

Either of those event should work as a trigger. Create
some code for the one of those events for the textbox you
want to save the value of. In that code, simple set the
value of the hidden textbox to the value of the current
textbox:

Me!txtHidden = Me!txtCurrent

Then using the BeforeUpdate or AfterUpdate event
(whichever fits your needs better), create code that
compares the current value against the value in the
hidden textbox:

if Me!txtCurrent.Value = Me!txtHidden.value Then
do something
else
do something else
end if

The hidden text box is a slick little way of holding
information on a form.

Hope this gives you some alternate ideas.

-dc
 
Back
Top