Prompt for User to Save Changes in a Form

G

Guest

I need a prompt for User to Save Changes in a Form. I got the following code
from the Microsoft Support Site. It seemed to work fine. But then it just
stopped working. When I checked the code again, it seemed to "remember"
again. I'm using a copy of Access 2000, and the support site says that this
code is for 95/97.
Should that make a difference? Here's the code:


-------------------------------------------------------------------------------
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.

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
 
A

Allen Browne

The code is fine for Access 2000, apart from the unnecessary test of
Me.Dirty. (Form_BeforeUpdate will not trigger if the form is not dirty.)

In order for it to work, the BeforeUpdate property of the *form* (not a
control) must be set to:
[Event Procedure]
Occassionally that property gets lost when you are modifying the form or its
code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top