By default the MsgBox function of VBA will default the choise to the first button on the form. i.e M

Message = MsgBox("Update the file?", vbYesNo, """Yes"" as the default")

Will instruction would display the following message box:

Defualt set as Yes

This, of course, is fine if you want the default response to be "Yes", but what if you want the default to be "No"?

The answer is to use the "vbDefaultButtonn" option. The vbDefaultButton should be added to the MsgBox type (i.e vbYesNo). The n value will depend on which button you want to make the default. To make "No" the default for the vbYesNo option you would code:

Message = MsgBox("Update the file?", vbYesNo + vbDefaultButton2, """No"" as the default")

This would reult in the following message box being displayed:

Default set to

If the MsgBox option has 3 buttons and you want to make the third button the default, you would use vbDefaultButton3.


That is all there is to it. Enjoy!
 
 
 


If you need any support or assistance with any of the code on this site
or
if you would like to contact us, please click here

follow us on facebook
Follow us on Facebook

 

Number of unique visitors 379

Copyright © Abbydale Systems LLC 2015-2024

Abbydale Systems LLC Lic. 802696149. All rights reserved.

Last modified : Saturday 2nd of April 2022