Creating a form that requires users to confirm/cancel changes

AnnieB

New member
Local time
Today, 11:18
Joined
Jun 24, 2013
Messages
2
I am fairly new to Access and my "changed" position at work requires that I learn much more about the software. My first challenge is to learn how to make an existing form prompt a user to confirm or cancel changes. I don't know anything about coding but I searched online and found some coded that is supposed to make this happen. I went to "form properties'' and typed this (below) in BeforeUpdate:

'If the form data has changed a message is shown asking if
'the changes should be saved. If the answer is no then
'the changes are undone

On Error GoTo BeforeUpdate_Error

If Me.Dirty Then
'if record has been changed the dirty property
' is set to true Display message to save the record
If MsgBox("The record has changed - do you want to save it?", _
vbYesNo + vbQuestion, "Save Changes") = vbNo Then
Me.Undo
End If
End If

BeforeUpdate_Exit:
Exit Sub

BeforeUpdate_Error:
MsgBox Err.Description
Resume BeforeUpdate_Exit


After saving changes to the design, I tested by changing the record. I received no prompt. Can you help?
 
You'll need to add the Cancel = 1 code which actually cancels the update.

Code:
If MsgBox("The record has changed - do you want to save it?", _
vbYesNo + vbQuestion, "Save Changes") = vbNo Then
[COLOR="Red"]Cancel = 1
[/COLOR]Me.Undo
End If
 
Adding this code seems to make a field from a subform appear on the form. Since I know so little, I think I may need to step back from this problem and learn more about writing code. Do you have any suggestions on a good strategy for this?
 

Users who are viewing this thread

Back
Top Bottom