Results 1 to 13 of 13
  1. #1
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    MsgBox Buttons Conundrum (VBA/All)

    When entering code for a MsgBox, Intellisense offers me the option of vbDefaultButton1 through vbDefaultButton4. I have no problem using the value for these settings in combination with other values, but have been unable to divine a method of using the intellisense selection method to (for example), select vbAbortRetryIgnore with the Retry button as default. Any clarification will be greatly appreciated.

    TIA
    Regards
    Don

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MsgBox Buttons Conundrum (VBA/All)

    Hey that is new to me, I never spotted those defaultbutton thingy's!

    Anyway, here is how to use them:

    MsgBox "test", vbDefaultButton3 + vbAbortRetryIgnore + vbCritical, "this is a test"
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: MsgBox Buttons Conundrum (VBA/All)

    You can add the constants for a) button types, [img]/forums/images/smilies/cool.gif[/img] icon and c) default button together using + or Or. After each + or Or, intellisense will pop up the complete list again.

    Dim intReturn As Integer
    intReturn = MsgBox("Do you want to continue?", vbAbortRetryIgnore + vbQuestion + vbDefaultButton2)

    You yourself will have to determine that Retry is the second button in AbortRetryIgnore, so you need vbDefaultButton2. IntelliSense won't tell you that. Neither will it prevent you from using the same constant twice.

  4. #4
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: MsgBox Buttons Conundrum (VBA/All)

    Thank you Jan and Hans. I had tried And and & as connectors without success; but never considered Or.
    Regards
    Don

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: MsgBox Buttons Conundrum (VBA/All)

    And and Or act as bitwise operations. And cancels out the different bits, Or combines them, as does + in this case. & is the string concatenation operator, it is not suitable for combining numeric values.

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    MsgBox Buttons (Inhibit)

    On, I hope, a related note, has anyone found a way to inhibit the defaults?
    I have a MsgBox with Yes/No/Cancel buttons.
    By default the Yes is focussed. As noted here I can cause the focus to rest on Yes or on No or on Cancel.

    I'd rather have no focus at all, because with focus, the mouse pointer rests on the focus, and the bored use is more likely to choose that button, or to tap the enter key (and hence gravitate towards a succession of Yes responses).

    Short of making up a small GUI to force the user to choose each time, is there a way to inhibit focus on a MsgBox?

    I've tried using (in my case) vbDefaultButton4 on a 3-button box. An invalid value seems to revert to the default=0.

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: MsgBox Buttons (Inhibit)

    I think you'll have to create a userform - the MessageBox API function (upon which the MsgBox VBA function is built) always has a default button.

  8. #8
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: MsgBox Buttons (Inhibit)

    Consider the following.
    <div style="width: 100%; background-color: #FFFFFF;"><code><font color=black><font color=blue>Public</font color=blue> <font color=blue>Sub</font color=blue> test()
    MsgBox "This is a test", vbYesNoCancel + vbMsgBoxHelpButton + vbDefaultButton4
    <font color=blue>End</font color=blue> <font color=blue>Sub</font color=blue>
    </font color=black></code></div hiblock>
    Regards
    Don

  9. #9
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MsgBox Buttons (Inhibit)

    > ... always has a default button.
    (sigh!) That's what I'd thought.
    Thanks for confirmation

  10. #10
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MsgBox Buttons (Inhibit)

    >Consider the following.
    Consider?
    I'll USE it (grin!).
    While not as neat as a homespun GUI, it has the advantage of immediate implementation.
    Setting the Help button as a non-functional default forces the user to choose one of the other buttons.

    If I had to find a downside, it would be that my user's mouse cursor still jumps to a button, so the user can't hover over, say, the "No" button.
    Making "No" the default won't make the "Yes" user happy.
    Automatically disabling the mouse "jump to default button' setting probably won't make either of them happy.

    Thanks anyway, Don, for a solution that works better than my default MsgBox.

  11. #11
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: MsgBox Buttons (Inhibit)

    >> mouse cursor still jumps to a button

    Mine doesn't; so I expect that there's a switch somewhere controlling this feature. Perhaps some other lounger can shed some light for us.
    Regards
    Don

  12. #12
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: MsgBox Buttons (Inhibit)

    Chris
    Does the info <!post=here,364866>here<!/post> help?
    Regards
    Don

  13. #13
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MsgBox Buttons (Inhibit)

    Thanks.

    > Does the info here help?
    "sort of" if I want to get into API programming just to move the mouse pointer away from the message box.
    I suspect I may as well draft my own little GUI form and make sure that not one button has focus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •