I'm afraid I'm beyond my expertise level on this one. I have some BeforeUpdate event code that I would like to figure out how to utilize in a single function to be run from the form's property events tab (passing the ActiveControl, or the Form itself) rather than having to enter VBA code in the form's VBA module for every data field on my Form. I'm seeing 2 issues here. It seems that the Ctrl.Undo command works ONLY in the BeforeUpdate event (?) AND I can't figure out a way to trigger the BeforeUpdate Cancel parameter via a called function. Code below. Any advice/suggestions would be appreciated.
Line 10 is a Form level toggle button that controls the application of the BeforeUpdate code to all bound data controls on the form (it's too easy to make accidental mods to an open Access data form in a multi-application, multi-monitor environment). The toggle gets turned "on" in the Form's current event. The user can manually turn the toggle to "off" and "on" if they are doing a bunch of updates to a record.
Line 20 just grabs the Form's ActiveControl
Line 30 firstly passes through any new records. If the record is already existing then the Confirm function asks the user if they really want to modify the value of the ActiveControl. If the user response is negative the ActiveControl is set back to its pre-edited value and the event chain is canceled.
Private Sub cbxTag_BeforeUpdate(Cancel As Integer)
Dim ctrl As Object
10 If Not Me.tglSafety.Caption = "P" (Windinga 2 font checkmark) Then Exit Sub
20 Set ctrl = Me.ActiveControl
30 If Me.NewRecord = False And Not Confirm(ctrl) Then ctrl.Undo:: Cancel = True
End Sub
Line 10 is a Form level toggle button that controls the application of the BeforeUpdate code to all bound data controls on the form (it's too easy to make accidental mods to an open Access data form in a multi-application, multi-monitor environment). The toggle gets turned "on" in the Form's current event. The user can manually turn the toggle to "off" and "on" if they are doing a bunch of updates to a record.
Line 20 just grabs the Form's ActiveControl
Line 30 firstly passes through any new records. If the record is already existing then the Confirm function asks the user if they really want to modify the value of the ActiveControl. If the user response is negative the ActiveControl is set back to its pre-edited value and the event chain is canceled.