Message Box Advice

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

New to this. Up until now I have only had the need to create the vbYesNo
message box style and passing the vbYes or vbNo response into an If Then
statement was very straightforward. I now need to create an information
message box for users so I think the style needs to be vbOkOnly but I'm not
sure what,if anything, I need to be doing in my code after the user has
clicked the OK box and acknowledged and cleared the message box. Generating
the message box is the last line in my subroutine - do I just go straight to
End Sub or should I have something in there to handle the vbOk in the same
sort of way as vbYes and vbNo are handled?
TIA
 
It depends on what you want to do and how you code it. If it is
informational only, and no response is required, the simplest form is"
MsgBox "Some Message Here"
That will present a message box with no repsonse required. The user will
see the message and there will be an ok button. The code halts until the user
clicks the button, hits enter or escape.
If you code it like this:
MsgBox("Some Message Here")
You will receive an error "Expected = ". With the parentheses, it is
expecting some response.

When you need to user to make a decision, then you use it like this:
intAnswer = MsgBox("Wanna Do Lunch", vbYesNo)
Then the variable intAnswer will contain an interger value depending on
whether the user selected yes or no.

Of course, you can also do
If MsgBox("Wanna Do Lunch", vbYesNo) = vbYes Then
Call OrderPizza
End If

You use the first form when you want to present a message to the user, but
expect no decision form him. You use the second form if some decision is
required.
You can still use constants in the first form to format the message box:
MsgBox "Some Message Here", vbInformation, "Box Top"
This will have "Box Top" as the title of the message box, it will make a
sound, and show the I icon.
 
Back
Top