Microsoft KB Archive/210326

= HOW TO: Create an AfterUndo Form Event in Access 2000 =

Article ID: 210326

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q210326



Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

IN THIS TASK
SUMMARY
 * Creating the AfterUndo Procedure
 * How to Use the AfterUndo Procedure

REFERENCES



SUMMARY
This article shows you how to create and use a form module procedure called AfterUndo. The AfterUndo procedure runs when edits made to the current record are undone.

NOTE: This article explains a technique demonstrated in the sample file, FrmSmp00.mdb. For information about how to obtain this sample file, please see the following article in the Microsoft Knowledge Base:

233324 ACC2000: Microsoft Access 2000 Sample Forms Database Available in Download Center

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

When you click Undo Record on the Edit menu or press the ESC key twice to undo changes to the current record in a form, there is no built-in form event that is triggered. The AfterUndo procedure simulates an AfterUndo event so that you can restore calculations that may have been set while the record was being edited.

back to the top

Creating the AfterUndo Procedure
To create the AfterUndo procedure, follow these steps:

  Open the form to which you want to add the AfterUpdate procedure in Design view, and then add a text box with the following properties to the form:   Name: txtEditModeChange ControlSource: =[Form].[Dirty] & CheckUndo([Form]) Visible: No                     Add the following event procedure to the AfterUpdate property of the form: Sub Form_AfterUpdate

' Because the record is being saved, which changes the edit mode, the ' bookmark should be reset so that it will appear to the CheckUndo ' function that the user moved to another record.

PrevBookmark = Null

End Sub   Create a module and type the following line in the Declarations section: Option Explicit Dim PrevBookmark   Type the following procedure: Function CheckUndo (F As Form) As Variant Dim CurrBookmark

' Is the record clean (not dirty)? If Not F.Dirty Then ' If so, get the current bookmark. On Error Resume Next CurrBookmark = F.bookmark

' If an error occurred, this is the new record. If Err Then CurrBookmark = "NewRecord"

' Determine if the edit change occurred on the same record (the     ' record was undone, as opposed to moving to another record). If StrComp(CurrBookmark, PrevBookMark, 0) = 0 Then ' The record was undone. AfterUndo Else ' The record was not undone (moved to another        ' record). Record the bookmark of the current ' record for the next iteration. PrevBookmark = CurrBookmark End If  End If

End Function

Sub AfterUndo ' Add the code you want to run when the record is undone here. End Sub 

back to the top

How to Use the AfterUndo Procedure
The following example demonstrates how to use the AfterUndo procedure:  Open the sample database Northwind.mdb.</li> Open the Employees form in Design view and follow steps 1 through 4 of the "Creating the AfterUndo Procedure" section earlier in this article.</li>  Modify the code in the AfterUndo procedure (created in step 4) as follows: Sub AfterUndo MsgBox "Record Changes Undone" End Sub </li> View the form in Form view.</li> Modify any field in any record in the form.</li> On the Edit menu, click Undo Current Field/Record. Note that the "Record Changes Undone" message box appears.</li> On the Edit menu, click Go To, and then click New Record.</li> Type any text in any field in the new record.</li> Press the ESC key. Note that the "Record Changes Undone" message box appears.</li></ol>

back to the top

<div class="references_section">