CancelEvent not working (1 Viewer)

momoko

Registered User.
Local time
Today, 18:35
Joined
Oct 7, 2001
Messages
41
Hi,
I've the following code but the cancel doesn't seem to be working, when upon click cancel, it should still remain on the form but it closed the form. Can someone please advise.

Dim strMsg As String
Dim strMsg2 As String
Dim strTitle As String
Dim strTitle2 As String
Dim intResponse As Integer

strMsg = "Do you wish to save changes?"
strMsg2 = "The changes you made were not saved."
strTitle = "Save Entry"
strTitle2 = "Entry Canceled"

If Me.Dirty Then
intResponse = MsgBox(strMsg, vbYesNoCancel, strTitle)
If intResponse = vbNo Then
Me.Undo
MsgBox strMsg2, vbOKOnly, strTitle2
ElseIf intResponse = vbCancel Then
DoCmd.CancelEvent
Me.SetFocus
End If
End If
 

ghudson

Registered User.
Local time
Today, 13:35
Joined
Jun 8, 2002
Messages
6,195
Very few "form" events support the cancel command. You can tell if cancel is an option if it is declared in the sub line like this in the forms BeforeUpdate event...
Private Sub Form_BeforeUpdate(Cancel As Integer)

I believe that you are trying to do this with a custom form close button and that is the wrong event for what you are trying to do and the cancel command will not work in your custom routine. You need to use the forms BeforeUpdate event. Search around for your question and problem is asked and answered almost daily.

Check out these two threads on how I prevent a user from moving to another record if the current record is dirty and also to prevent closing a form [and the application] if the user does not do what I want.

A better mouse trap?

Enable/Disable The Control Box X Button
 

Users who are viewing this thread

Top Bottom