Message Box Response?

M

Microsoft

Word 2000

It seems like I should be able to figure this out, but I just can't get
it working. I have the following code that displays a message box with
Yes and No buttons. No matter which button I click in the message box,
the code always takes the same branch of the IF statement. Can someone
tell me what I'm doing wrong?

Sub TestMessageBox()

Dim Response As Boolean

' Sets the message box elements.
mbMessage = "Did the document print successfully?"
mbStyle = vbQuestion + vbYesNo + vbDefaultButton2
mbTitle = "Document Printed?"

' Displays the message box.
Response = MsgBox(mbMessage, mbStyle, mbTitle)

' Branches based on the message box response.
If Response = vbYes Then
MsgBox "Yes"
Else
MsgBox "No"
End If

End Sub

--Tom
 
J

JB

Microsoft said:
Word 2000

It seems like I should be able to figure this out, but I just can't get
it working. I have the following code that displays a message box with
Yes and No buttons. No matter which button I click in the message box,
the code always takes the same branch of the IF statement. Can someone
tell me what I'm doing wrong?

Sub TestMessageBox()

Dim Response As Boolean

' Sets the message box elements.
mbMessage = "Did the document print successfully?"
mbStyle = vbQuestion + vbYesNo + vbDefaultButton2
mbTitle = "Document Printed?"

' Displays the message box.
Response = MsgBox(mbMessage, mbStyle, mbTitle)

' Branches based on the message box response.
If Response = vbYes Then
MsgBox "Yes"
Else
MsgBox "No"
End If

End Sub

--Tom
Hi Tom,
You've dimmed Response as Bool when it should be Int/Long as VBYes or
VBNo will return numeric values.

VBYes being 6 If I remember right.

Just Dim Response as Long and see what that does.

HTH

J
 
T

Thomas M

You may have noticed that on my original post the From line says
"Microsoft". Let me just say that I am not affiliated with Microsoft in
any way. I just accidentally put the wrong thing in the wrong place when
I was configuring my news reader (Meant to put "Microsoft" as the
*server* name, and not as my name).

I tried your suggestion, and it works. Now that I know the solution, it
seems obvious. I read in Help last night (before posting my question)
where vbYesNo returns 6 (Yes) or 7 (No). So I stupidly tried:

If Response = 6 Then

DOH! Hey, it was 5:38 AM. What more can I say? :)

I was thinking of it in terms of a boolean response because the response
would be either yes (True) or no (False). But, of course, there are two
different buttons, and in order for the application to know which button
was clicked, the message box would have to return a numeric. So while
the user's decision can be thought of in boolean terms, the *value*
returned by the message box is not boolean.

--Tom
 

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