How to tell if a field on a form has changed? A control?

R

rc51wv

Is there a control that returns a variable that will let you know if
information in a field on a form that has a table set as it's recordsource
has changed from the table?

Say field PIN has had the number changed from what was there when the form
was loaded, is there a control that will return a true/false answer that I
can use on at close to let me know that the field has changed?

Right now all I have is storing the initial values from the fields on the
form in a global variable and then comparing them on close to see if that
information is different.
 
M

Marshall Barton

rc51wv said:
Is there a control that returns a variable that will let you know if
information in a field on a form that has a table set as it's recordsource
has changed from the table?

Say field PIN has had the number changed from what was there when the form
was loaded, is there a control that will return a true/false answer that I
can use on at close to let me know that the field has changed?

Right now all I have is storing the initial values from the fields on the
form in a global variable and then comparing them on close to see if that
information is different.


Bound controls have the OldValue property that you can use
to do that. The OldValue property will change when the
record is saved so you need to check in the form's
BeforeUpdate or AfterUpdate event, depending on what you
want to do when the value is changed.
 
L

Linq Adams via AccessMonster.com

You're doing this for an audit trail, maybe? How many controls are you
talking about? I ask because this is a rather duty task if you're talking
about a lot of controls, and could probably be done better looping thru the
controls and checking using OldValue as Marshall has suggested.

The problem with using Global Variables is that they'll lose their values if
an error occurs. I've never had the problem, knock wood, I've always been a
freak on error handling.

Also, if this is part of an audit routine, Allen Browne has an excellent demo
set up for this on his site.
 
L

Linq Adams via AccessMonster.com

Meant to add that I think the Form_AfterUpdate event is too late for this,
because the record has been saved at this point. Think it would have to be
the Form_BeforeUpdate event.
 
M

Marshall Barton

Linq said:
Meant to add that I think the Form_AfterUpdate event is too late for this,
because the record has been saved at this point. Think it would have to be
the Form_BeforeUpdate event.


You're right.

I meant an individual control's AfterUpdate event, but I
can't type as fast as I can dictate ;-)
 

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