Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error 2115: Macro/function set to BeforeUpdate/ValidationRule is preventing {pgm} from saving data in the field

Tags:

vba

ms-access

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.

like image 771
mwolfe02 Avatar asked Sep 01 '25 10:09

mwolfe02


1 Answers

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:

  1. Create a new form
  2. Specify a RecordSource for the form (i.e., make it a bound form)
  3. Add a subform control (note: there is no need to assign a SourceObject to the subform control)
  4. Set the Form BeforeUpdate property to [Event Procedure]
  5. Add the following code to the form's code module:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
        DoEvents
    End Sub
    
  6. Make a change to the data on the main form
  7. Click directly on the subform control
  8. Receive error message noted in the question
like image 103
mwolfe02 Avatar answered Sep 03 '25 15:09

mwolfe02