T
Tony Williams
I have a form with a command button that the user clicks to close the form.
The code behind the button checks if the record is a new one and a message
appears. I want to also check whether or not an existing record has been
changed and if so a different message appears and if the user has viewed the
record and made no change then no message appears. here is my code, how can
I change it to get the three options?
TIA
Tony Williams
Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click
If Me.NewRecord Then
If vbYes = MsgBox("Do you want to save this new record?", 36, "Enter New
Record") Then
DoCmd.Requery "Docnumtxt"
DoCmd.RunCommand acCmdSaveRecord
Else
Me.Undo
Cancel = True
End If
Else
If Me.NewRecord = False Then
If vbYes = MsgBox("Do you want to save any changes you have made to this
record?", 36, "Save Changes") Then
DoCmd.RunCommand acCmdSaveRecord
Else
Me.Undo
End If
End If
End If
DoCmd.Close
Exit_cmdClose_Click:
Exit Sub
Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click
The code behind the button checks if the record is a new one and a message
appears. I want to also check whether or not an existing record has been
changed and if so a different message appears and if the user has viewed the
record and made no change then no message appears. here is my code, how can
I change it to get the three options?
TIA
Tony Williams
Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click
If Me.NewRecord Then
If vbYes = MsgBox("Do you want to save this new record?", 36, "Enter New
Record") Then
DoCmd.Requery "Docnumtxt"
DoCmd.RunCommand acCmdSaveRecord
Else
Me.Undo
Cancel = True
End If
Else
If Me.NewRecord = False Then
If vbYes = MsgBox("Do you want to save any changes you have made to this
record?", 36, "Save Changes") Then
DoCmd.RunCommand acCmdSaveRecord
Else
Me.Undo
End If
End If
End If
DoCmd.Close
Exit_cmdClose_Click:
Exit Sub
Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click