Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2004

Tip: Looking for answers? Try searching our database.

Message Box Response?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Microsoft - 08 Nov 2004 12:22 GMT
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
JB - 08 Nov 2004 12:38 GMT
> Word 2000
>
[quoted text clipped - 26 lines]
>
> --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
Thomas M - 09 Nov 2004 08:29 GMT
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

> > Word 2000
> >
[quoted text clipped - 37 lines]
>
> J
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.