message box yes/no

J

jackrobyn1

I have a picture that I want to use as a button to close the database. What
can i put in the properties/ on click to make a message box appear and ask
"are you sure you want to close?"............. obviously yes means close and
no means dont close.
 
R

Rastro

If msgbox ("Are you sure you want to close?", vbyesno +
vbDefaultButton2,"Closing application")=vbno then exit sub

this shortest sentence that I can imagine. The vbDefaultButton2 is to set
"no" as default
 
J

jackrobyn1

Am I doing something wrong? I've just pasted it in just as it is but it
doesn't work... just comes up with,
*The expression may not result in the name of a macro, the name of a
user-defined function, or[event procedure].
*There may have been an error evaluating the function, event or macro.

I'm a complete beginner so i must have done something wrong... sorry! Any
idea what i'm doing wrong?
 
R

Rastro

You should put the sentence into the click event of the "close" button, in
the first place.
The code should be something like this

private sub Close_click (...)

If MsgBox("Are you sure you want to close?", _
vbYesNo + vbDefaultButton2, "Closing application") = vbNo Then Exit
Sub
DoCmd.close

end sub

And maybe the error was in pasting as it is because the complete sentence is
only one line and you paste two because you see it in two lines.
Now I add a "_" in the middle to let you paste as you read it.

jackrobyn1 said:
Am I doing something wrong? I've just pasted it in just as it is but it
doesn't work... just comes up with,
*The expression may not result in the name of a macro, the name of a
user-defined function, or[event procedure].
*There may have been an error evaluating the function, event or macro.

I'm a complete beginner so i must have done something wrong... sorry! Any
idea what i'm doing wrong?

Rastro said:
If msgbox ("Are you sure you want to close?", vbyesno +
vbDefaultButton2,"Closing application")=vbno then exit sub

this shortest sentence that I can imagine. The vbDefaultButton2 is to set
"no" as default


"jackrobyn1" <[email protected]> escribió en el
mensaje
de noticias:[email protected]...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top