G
Garret
Hello, I have a form where there are two main ways to save. The first
is doing anything to move off of the current record, so that Access
wants to save it anyway, and its Before & After update triggers. Here
I have this code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
'if a record has been changed
If Form.Dirty = True Then
'prompt the user to save
ans = MsgBox("You have changed a record. Do you want to save?",
vbYesNoCancel + vbQuestion, "Save Record?")
If ans = 7 Then 'if user selects 'No'
Me.Undo 'undo the changes
ElseIf ans = 2 Then 'if user selects
'Cancel'
Cancel = True 'don't undo, don't save
End If
End If
End Sub
I also have the second way, a command button that uses the default
code:
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Exit_cmdSave_Click:
Exit Sub
Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click
End Sub
Whenever the command button is pressed, the BeforeUpdate action is
triggered first anyway, and the messagebox I created pops up. The
problem is, when I press Cancel, it says "DoMenuItem action canceled"
in a popup box. When I close the form, if the record was not saved and
the message box pops up, if the user presses cancel, then an error
message says "You can't save this record at this time...close database
anyway?"
How can I prevent the "Domenuitem action canceled" box from coming up,
and how can I make the close action become canceled if the user presses
cancel to save?
is doing anything to move off of the current record, so that Access
wants to save it anyway, and its Before & After update triggers. Here
I have this code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
'if a record has been changed
If Form.Dirty = True Then
'prompt the user to save
ans = MsgBox("You have changed a record. Do you want to save?",
vbYesNoCancel + vbQuestion, "Save Record?")
If ans = 7 Then 'if user selects 'No'
Me.Undo 'undo the changes
ElseIf ans = 2 Then 'if user selects
'Cancel'
Cancel = True 'don't undo, don't save
End If
End If
End Sub
I also have the second way, a command button that uses the default
code:
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Exit_cmdSave_Click:
Exit Sub
Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click
End Sub
Whenever the command button is pressed, the BeforeUpdate action is
triggered first anyway, and the messagebox I created pops up. The
problem is, when I press Cancel, it says "DoMenuItem action canceled"
in a popup box. When I close the form, if the record was not saved and
the message box pops up, if the user presses cancel, then an error
message says "You can't save this record at this time...close database
anyway?"
How can I prevent the "Domenuitem action canceled" box from coming up,
and how can I make the close action become canceled if the user presses
cancel to save?