Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ms Access Message boxes 2

Status
Not open for further replies.

4808

Programmer
Jan 13, 2004
27
GB
HI,
I am trying to create a button on a form to exit the database application that i am developing. this is the senario - when the Exit button is clicked a message comes up asking ' are you sure you want exit now? You get a yes and no button but so far they dont work.
 
This is what I usually use for something like you want to do. This code would go in the OnClick of the button.

strQuestion = MsgBox("Are you sure you want to exit?", vbYesNo)

If strQuestion = vbYes Then
DoCmd.Quit
Elseif strQuestion = vbNo then
Exit Sub
Endif
 
mkov

Your code would work fine, but you don't actually need the Elseif section, because you don't want anything to be run if they click "No"

John
 
The MsgBox function returns an integer, and it appears that you are assigning the result into a string. You might try changing strQuestion, if it is declared as a string, to intQuestion, defined as an integer.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
jrbarnett,

You are correct, I just have a habit of using Elseif even when it isn't needed. When I learned VBA, that is the way I was taught and am still trying to break the habit.
 
mkov

In fact, it can be even simpler:
Code:
If MsgBox("Are you sure you want to exit?", vbYesNo) = vbYes Then
    DoCmd.Quit
Endif

that's all you need.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top