Message box

deejay_totoro

Registered User.
Local time
Today, 20:46
Joined
May 29, 2003
Messages
169
Hello,

I am trying to create a simple message box but seem to be having some difficulty!

I would like a message box to appear saying:

"Do you want to exit?" with the buttons, Yes or No available to the user.

If the user clicks yes the database will close. However if the user clicks no, the message box should disappear (nothing happens.)

Any help anyone?

Thanks!

dj_T
 
Code:
if msgbox("Exit?",4) = 6 then
 exit sub
Else
 do something else
end if


???
kh
 
Deejay

If MsgBox("Do you wish to exit?", vbYesNo, "Exit Form") = vbYes Then

Application.Quit

End If

Allan
 
If MsgBox("Do you wish to exit?", 36, "Exit Form") = vbYes Then

Application.Quit

End If


:)
 
I would suggest that it is better practice to use the anmed constants, for easier reading at a later date...

if MsgBox("Do you wish to exit?", vbQuestion + vbYesNo, "Exit Form") = vbYes Then

Plus I would even suggest that you default the answer to "No", so pressing the enter key on the msgbox takes the "least harmful" option...

if MsgBox("Do you wish to exit?", vbQuestion + vbYesNo + vbDefaultButton2, "Exit Form") = vbYes Then

Regards

John.
 
Ach, what the hell.....


Code:
If MsgBox("Would you like to quit?", vbYesNo + vbQuestion, "Quit?") = vbNo Then Exit Sub
DoCmd.Quit

or:

Code:
If MsgBox("Would you like to quit?", vbYesNo + vbQuestion, "Quit?") = vbYes Then DoCmd.Quit
 
Or:

Code:
If MsgBox("Would you like to quit?", vbYesNo + vbQuestion, "Quit?") Then DoCmd.Quit

:)
 
KenHigg said:
Or:

Code:
If MsgBox("Would you like to quit?", vbYesNo + vbQuestion, "Quit?") Then DoCmd.Quit

But the value of vbNo is 7 and not 0. ;)
 
But it would still work, right? If all you wanted to do was quit..?
 
KenHigg said:
But it would still work, right? If all you wanted to do was quit..?

It would quit if you choose Yes or No though.

As the IF keyword expects a boolean where 0 is false and -1 is true. All numbers that are not 0 are considered to be true though.

So, selecting vbYes (6) or vbNo (7) would both be true.
 

Users who are viewing this thread

Back
Top Bottom