samedi 7 juin 2014

ms Closing the form ask save yesnocancel


Vote count:

0




I have put the VBA in Unload Form Event



Private Sub Form_Unload(Cancel As Integer)

Dim strMsg As String
Dim iResponse As Integer

' Specify the message to display.
strMsg = "Do you wish to save the changes?" & Chr(10)
strMsg = strMsg & "Click Yes to Save or No to Discard changes."

' Display the message box.
iResponse = MsgBox(strMsg, vbQuestion + vbYesNoCancel, "Save Record?")

' Check the user's response.
If iResponse = vbYes Then

' Undo the change.
DoCmd.RunCommand acCmdSave
End If

If iResponse = vbNo Then


' Undo the change.
DoCmd.RunCommand acCmdUndo
End If



If iResponse = vbCancel Then

' Undo the change
Cancel = True


End If



End Sub


If data is changed then the above code is working fine, then yes to save & close, No to undo & close and cancel to cancel event and remain on the form but when the data is unchanged then Yes button is working fine, but NO button do not close the form


Where I m mistaking ?



asked 56 secs ago






Aucun commentaire:

Enregistrer un commentaire