ACC: How to Prompt User to Save Changes to Record in a Form (95/97)ID: Q175911
|
Moderate: Requires basic macro, coding and interoperability skills.
When you move to the next record on a form or close a form, Microsoft
Access automatically saves any changes that you have made to the current
record. This article shows you how to use a BeforeUpdate event procedure to
prompt you to verify the save operation before Microsoft Access will continue.
This article assumes that you are familiar with Visual Basic for
Applications and with creating Microsoft Access applications using the
programming tools provided with Microsoft Access. For more information
about Visual Basic for Applications, please refer to your version of the
"Building Applications with Microsoft Access" manual.
CAUTION: Following the steps in this example will modify the sample
database Northwind.mdb. You may want to back up the Northwind.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 Microsoft Access will save the
record:
Private 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.
Dim ctl As Control
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?", vbYesNo + vbQuestion, _
"Save Record") = vbNo Then
Me.Undo
End If
End If
Exit_BeforeUpdate:
Exit Sub
Err_BeforeUpdate:
MsgBox Err.Number & " " & Err.Description
Resume Exit_BeforeUpdate
End Sub
For more information about the Controls collection, search the Help Index
for "Controls collection."
For more information about the For Each loop, search the Help Index for
"For Each...Next Statement."
Additional query words: inf
Keywords : FmsEvnt PgmPrcs
Version : WINDOWS:7.0,97
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: April 20, 1999