Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generic Code for the Active Control(s) on a Subform

Status
Not open for further replies.

Eutychus

Programmer
Nov 14, 2007
61
US
I want a generic procedure to test bound fields on a subform for updating or changing of the value and then sending a message to the user when the value changes. I do not want to send the message the first time the user enters data, but only if he/she changes it. Also, I want this procedure to be able to apply to any control on the subform. So if I have 5 fields, I want to put the code behind, say, the BeforeUpdate event and send the warning. I can do this for a single field by referring to the field explicitly. But I want to use the same code for any field on the subform. Can some combination of the ActiveControl property and the OldValue property (old value is null?) be applied to fields on a subform. I've tried various combinations of code in VBA and can't seem to get it right. I'm using Access 2003. I've searched tek-tips and other places and can't seem to find an answer. Any help would be greatly appreciated!
 
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Form_BeforeUpdate event, combined with the NewRecord property might fix your problem.

HTH

[pipe]
Daniel Vlas
Systems Consultant

 
I got it to work. Here's the code:

If IsNull(Screen.ActiveControl.OldValue) = False Then
MsgBox "Warning! Changing this value may invalidate the Doc Retrieval button. The Old Value is --> " & Screen.ActiveControl.OldValue, vbCritical, "MySystem System Message"
End If

Simple, huh? I was sure I had tried the reference "Screen.ActiveControl.OldValue" and it failed. Today I decided to try it again on another subform and it worked. I put the code in a public module and run it with a macro. I then just have to add the macro to the BeforeUpdate event on any bound field and it works. I must have done something wrong the first time. Thanks for your input, y'all!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top