ACC2: How to Prompt User to Save Changes to Record in FormID: Q181820
|
Moderate: Requires basic macro, coding and interoperability skills.
When you move to the next record or close a Microsoft Access form,
Microsoft Access automatically saves any changes that you have made to the
current record. This article demonstrates how to use a BeforeUpdate event
procedure that prompts you to verify the save operation before continuing.
CAUTION: Following the steps in this example will modify the sample
database NWIND.MDB. You may want to back up the NWIND.MDB file
and perform these steps on a copy of the database.
This example uses the BeforeUpdate event procedure in the Customers form to
prompt the user to confirm changes before saving.
Sub Form_BeforeUpdate (Cancel As Integer)
' This procedure checks to see if the data on the form has
' changed. If the data has changed, the procedure prompts the
' user to continue the save operation or cancel it. Then the
' action that triggered the BeforeUpdate event is completed.
On Error GoTo Err_BeforeUpdate
' The Dirty property is True if the record has been changed.
If Me.Dirty Then
' Prompt to confirm the save operation.
If MsgBox("Do you want to save?", 4 + 32, _
"Save Record") = 7 Then
Cancel = True
SendKeys "{ESC}"
End If
End If
Exit_BeforeUpdate:
Exit Sub
Err_BeforeUpdate:
MsgBox CStr(Err) & " " & Error(Err)
Resume Exit_BeforeUpdate
End Sub
For more information about how to prompt a user to save a record in
Microsoft Access 7.0 or 97, please see the following article in the
Microsoft Knowledge Base:
Q175911 ACC: How to Prompt User to Save Changes to Record in
Form(95/97)
For more information about undoing the current record in the BeforeUpdate
event, please see the following article in the Microsoft Knowledge Base:
Q97525 ACC: UndoCurrentRecord in BeforeUpdate Property Causes Error
Additional query words: inf saving ask asking
Keywords : FmsEvnt PgmPrcs
Version : WINDOWS:2.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: July 20, 1999