I have a bound form with a subform. When I make a change to the main form and then click on the subform, I get the following error:
The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing {program name} from saving the data in the field.
- If this is a macro, open the macro in the Macro window and remove the action that forces a save (for example, GoToControl).
- If the macro includes a SetValue action, set the macro to the AfterUpdate property of the control instead.
- If this is a function, redefine the function in the Module window.
If I make a change on the main form, then click on the record selector box or press Shift+Enter to save, and then click on the subform I do not get the error message.
It turns out the culprit was a call to DoEvents in the Form_BeforeUpdate procedure. The simplest solution is to remove the call to DoEvents.
In my particular case, the call to DoEvents was buried deep down in the call stack, so be sure to follow all of your code paths or just do a global search on DoEvents.
To reproduce this error:
[Event Procedure]Add the following code to the form's code module:
Private Sub Form_BeforeUpdate(Cancel As Integer)
DoEvents
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With