MSGBOX Problems....

  • Thread starter Thread starter James
  • Start date Start date
J

James

Hi I have the following code:

MsgBox "Are you sure you wish to Quit?",
vbYesNoCancel, "Quit?"
If vbYes Then DoCmd.Close
Else
DoCmd.CancelEvent
End If

It doesnt work... I click on Yes it closes... I click on
No it closes I click on Cancel it Closes....

Why??

Any help appreciated...

Many Thanks

James
 
James,

You need to use a variable to assign the value returned by the button
clicked, and then evaluate the variable's value; so, modify your code as
follows:

MyVar = MsgBox ("Are you sure you wish to Quit?", vbYesNoCancel, "Quit?")
If MyVar = vbYes Then
DoCmd.Close
Else
DoCmd.CancelEvent
End If

HTH,
Nikos
 
try
if MsgBox ("Are you sure you wish to Quit?", vbYesNoCancel, "Quit?")= vbYes
Then
DoCmd.Close
Else
DoCmd.CancelEvent
End If

Ed
 
Back
Top