Brian said:
Hallo,
Thanx for the reply.
The form_beforeUpdate has the below code. I was thinking to refer to
this instead of 2 save actions. So a user can click the save button
or if not clicked save be reminded on leaving the record through form_
beforeupdate...
Private Sub Form_BeforeUpdate(cancel As Integer)
Msg = "Save changes?"
Style = vbYesNo + vbQuestion
Title = "Mydatabase"
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
'do nothing
Else
DoCmd.RunCommand acCmdUndo
End If
End Sub
If you want to display the "Save changes?" prompt only if the user
hasn't clicked the Save button, why not use a module-level flag variable
to tell the routine that the button was clicked. The relevant parts of
the form's code module might look something like this:
'----- start of code ------
Option Compare Database
Option Explicit
Dim mblnClickedSave As Boolean 'Set to True when user clicks "Save"
Private Sub CmdSave_Click()
On Error GoTo Err_CmdSave_Click
If Me.Dirty Then
mblnClickedSave = True
RunCommand acCmdSaveRecord
End If
Exit_CmdSave_Click:
Exit Sub
Err_CmdSave_Click:
MsgBox Err.Description
Resume Exit_CmdSave_Click
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Msg As String
Dim Title As String
Dim Style As Integer
If mblnClickedSave Then
' Reset flag for next time
mblnClickedSave = False
Else
Msg = "Save changes?"
Style = vbYesNo + vbQuestion
Title = "Mydatabase"
Response = MsgBox(Msg, Style, Title)
If Response <> vbYes Then
Cancel = True
DoCmd.RunCommand acCmdUndo
End If
End If
End Sub
'----- end of code ------
I haven't tried that out, and I'm not sure whether setting Cancel = True
in the BeforeUpdate event procedure (combined with Undoing the form) is
something you should do or if it's going to cause a problem, but you get
the idea.