Project: MsgBox Function Always Has First Button as Default
  
PSS ID Number: Q124535
Article last modified on 12-13-1995
 
4.00    | 4.00
 
WINDOWS | MACINTOSH
 

--------------------------------------------------------------------
The information in this article applies to:
 
 - Microsoft Project for Windows, version 4.0
 - Microsoft Project for the Macintosh, version 4.0
--------------------------------------------------------------------
 
SYMPTOMS
========
 
In Microsoft Project 4.0, when you create a Visual Basic, Applications
Edition, macro, the MsgBox function can be used to display a message box
with one, two, or three buttons. However, the first button in the message
box will always be the default button, even when vbDefaultButton2 or
vbDefautButton3 is used in the buttons argument to specify the second or
third button as the default.
 
WORKAROUND
==========
 
To make the second or third button in a message box the default, use the
SendKeys statement to send one or two TAB characters before you call the
MsgBox line. Using SendKeys to send tab characters to the dialog box will
give focus to the appropriate button in the dialog box.
 
For example, when the following two lines of code are executed, a message
box is displayed with Yes, No, and Cancel buttons, and the Cancel button
has focus.
 
Microsoft provides examples of Visual Basic procedures for illustration
only, without warranty either expressed or implied, including but not
limited to the implied warranties of merchantability and/or fitness for a
particular purpose. This Visual Basic procedure is provided 'as is' and
Microsoft does not guarantee that it can be used in all situations.
Microsoft does not support modifications of this procedure to suit customer
requirements for a particular purpose.
 
Sample Visual Basic Code
------------------------
 
   Sub messagebox()
       SendKeys "{¬Tab 2}"
       MsgBox prompt:="Hello", buttons:=vbYesNoCancel
   End Sub
 
STATUS
======
 
Microsoft has confirmed this to be a problem in the products listed at the
beginning of this article. We are researching this problem and will post
new information here in the Microsoft Knowledge Base as it becomes
available.
 
MORE INFORMATION
================
 
The "buttons" argument of the MsgBox function includes options to specify
the number and kind of buttons to be displayed in a message box and to
specify which button is the default. The default button is the button that
has focus when the message box is displayed. A message box can have one,
two, or three buttons, and the constants vbDefaultButton1,
vbDefaultButton2, and vbDefaultButton3 can be used in the buttons argument
to specify which is the default. For example, the following line of code
specifies a message box with Yes, No, and Cancel buttons, with Cancel as
the default:
 
   Sub messagebox()
       MsgBox prompt:="Hello", buttons:=vbYesNoCancel + vbDefaultButton3
   End Sub
 
However, when the above line is executed, the Yes button is the default.
 
For more information about the MsgBox function, choose the search button in
Microsoft Project 4.0 Visual Basic Reference, and type the following:
 
   MsgBox
 
KBCategory: kbprg kbcode
KBSubcategory:
 
Additional reference words: 4.00
=============================================================================
Copyright Microsoft Corporation 1995.
