Yes No Message Box

P

Playa

I have a message box with yes/no buttons. When the message box is displayed
and user clicks the Yes button I want the form to save and close, if the user
clicks the No button I want the form to stay open and not save. Here is the
code I have...

MsgBox "The Drawing Number CANNOT be changed after it is saved! Is the
Drawing Number Correct?" _
, vbYesNo, "Drawing Number Text Box"

If vbYes Then
..........................................
..........................................
End If

If vbNo Then
...........................................
...........................................
End If


As of right now no matter which button is pressed the form always gets saved
and closed. How do I properly code it so that when the different buttons are
pressed, I will get different results?

Thanks in advance.
 
G

Gerald Stanley

Try the construct

If MsgBox ("The Drawing Number CANNOT be changed after it is saved! Is the
Drawing Number Correct?" , vbYesNo, "Drawing Number Text Box" ) = vbYes Then
do something
Else
do something else
End If

Hope This Helps
Gerald Stanley MCSD
 
F

fredg

I have a message box with yes/no buttons. When the message box is displayed
and user clicks the Yes button I want the form to save and close, if the user
clicks the No button I want the form to stay open and not save. Here is the
code I have...

MsgBox "The Drawing Number CANNOT be changed after it is saved! Is the
Drawing Number Correct?" _
, vbYesNo, "Drawing Number Text Box"

If vbYes Then
..........................................
..........................................
End If

If vbNo Then
...........................................
...........................................
End If

As of right now no matter which button is pressed the form always gets saved
and closed. How do I properly code it so that when the different buttons are
pressed, I will get different results?

Thanks in advance.

You haven't stated where you have placed your code, nor what your
actual code is!

To prevent the form from closing, place the following in the Form's
Unload event:

If MsgBox("The Drawing Number CANNOT be changed after it is saved! Is
the Drawing Number Correct?" , vbYesNo, "Drawing Number Text
Box""Save?") = vbNo Then
Cancel = True
End If

Watch out for line wrap above.
Though actually i think you should close the form independently of
saving the record.
Place the same above code in the Form's BeforeUpdate event instead of
the Form's Unload event.
 

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