Microsoft KB Archive/92810

= ACC: BeforeUpdate Macro Appears to Be Running Twice =

Article ID: 92810

Article Last Modified on 1/18/2007

-

APPLIES TO


 * Microsoft Access 1.0 Standard Edition
 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q92810



Novice: Requires knowledge of the user interface on single-user computers.



SYMPTOMS
The BeforeUpdate macro appears to be running twice rather than only once.



CAUSE
The BeforeUpdate macro will run whenever an edited record is saved. And if you add records using the Paste Append command, it will run when each of those records is added. If you find that the BeforeUpdate macro is running more than once, check to see exactly what actions you are taking.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
 Create a macro with a MsgBox action and a CancelEvent action. Save this macro as Macro1. Create a form based on any table and add a text box. Set the form's BeforeUpdate property to the Macro1 macro. View the form in Form view.</li> Enter data in a field, and then select the data in that field.</li> On the Edit menu, click Copy.</li> On the Edit menu, click Paste Append.</li> Click OK when the Message box (that you created in the Macro1 macro) appears.</li> Close the form.</li> Click OK when the Message box (that you created in the Macro1 macro) appears.</li> Click OK when the following error message appears.

In Microsoft Access 7.0 and 97:

You can't save this object at this time. Microsoft Access may have encountered an error while trying to save a record. If you close the object now, the changes you made will be lost. Do you want to close the database object anyway?

In Microsoft Access versions 1.x and 2.0:

The record being edited can't be saved. If you close the form, the changes you've made to the record will be lost. Close anyway?

</li></ol>

Note that the message box you created in Macro1 reappeared in step 11. The macro that you assigned to the BeforeUpdate property is running twice: once when the record that you added using the Paste Append command is saved, and twice when the edited record is saved.

<div class="references_section">