message box with yes/no option

A

Alylia

Hello,

I have a command button on my Travel Details (TD) form that takes you back
to main switchboard. On the TD form there a number of text boxes that hold
temporary data for as long as the form is active.
If a user by mistake exits this form all the temporary data are lost. I
would therefore like to have a message box that comes up with the question
"Do you want to exit the TD form? also with "Yes" or "No" option before the
user can exit the form.
 
S

SusanV

If MsgBox("Are you sure you want to exit and lose all data?", vbYesNo,
"Exit?") = vbYes Then
DoCmd.Close acForm, "YourFormName"
Else
'do nothing
End If
 
A

Al Camp

Alylia,
Use the OnUnload event. It has a Cacel function...

Private Sub Form_Unload(Cancel As Integer)
Dim Response As Variant
Response = MsgBox("Do you want to exit the TD form?", vbYesNo)
If Response = vbNo Then
Cancel = True
End If
End Sub
 
Top