Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Home > TechHelp > Directory > Access > MsgBox Options < Force Change PW 3 | MsgBox Options 2 >
MsgBox Options
By Richard Rost   Richard Rost on LinkedIn Email Richard Rost   3 years ago

Access MsgBox Options. Set No as Default


 S  M  L  XL  FS  |  Slo  Reg  Fast  2x  |  Bookmark Join Now

In this Microsoft Access tutorial, I'm going to teach you how to change the default button in a message box so it's not the first one. This way, you can have "No," "Cancel," or any other type of button as your default option. We'll also discuss other properties of a message box, such as the icon, sound, and all that good stuff.

Jasper from Euless, Texas (a Platinum Member) asks: I've been using a MsgBox in my program to double-check with users before they delete a lot of data. The problem is, if they hit a key by accident, the message box defaults to "Yes," which could cause important data to be erased. I tried to reword the message to make "Yes" cancel the deletion, but it doesn't sound right. "This will delete data. Would you like to CANCEL this request?" It sounds dumb. Is there a way to simply change it so that the default button is "No?"

Prerequisites

Links

Recommended Courses

Up Next

Learn More

FREE Access Beginner Level 1
FREE Access Quick Start in 30 Minutes
Access Level 2 for just $1

Free Templates

TechHelp Free Templates
Blank Template
Contact Management
Order Entry & Invoicing
More Access Templates

Resources

Diamond Sponsors - Information on our Sponsors
Mailing List - Get emails when new videos released
Consulting - Need help with your database
Tip Jar - Your tips are graciously accepted
Merch Store - Get your swag here!

Questions?

Please feel free to post your questions or comments below or post them in the Forums.

KeywordsMsgBox Options in Microsoft Access

TechHelp Access 2016, Access 2019, Access 2021, Access 365, Microsoft Access, MS Access, MS Access Tutorial, #msaccess, #microsoftaccess, #help, #howto, #tutorial, #learn, #lesson, #training, #database, Set No as Default, Customize MsgBox, Change Default Button, VBA MessageBox, MsgBox Icons, MsgBoxConfiguration, Confirmation Dialog, MsgBox Default No, VBA MsgBox Tutorial, VBA Dialog Boxes, Access MsgBox Customization, Customize Confirmation Box, MsgBox Command Syntax

 

 

 

Start a NEW Conversation
 
Only students may post on this page. Click here for more information on how you can set up an account. If you are a student, please Log On first. Non-students may only post in the Visitor Forum.
 
Subscribe
Subscribe to MsgBox Options
Get notifications when this page is updated
 
Intro In this video, we will talk about the different options available when using the MsgBox function in Microsoft Access VBA. We will cover how to display various button combinations, add icons, get responses from users, and most importantly, how to set a button other than YES as the default, which is especially useful for actions like confirming deletions. We'll also discuss some message box trivia, options that no longer work, and a few special settings like text alignment.
Transcript Today we're going to talk about message box options. There are a whole bunch of options you can set when you're using message boxes. We're going to talk about the icons and the buttons you can have, the responses, and all that stuff. Most importantly, I'm going to show you how to set NO as the default option instead of yes.

Today's question comes from Jasper in Ulyss, Texas, one of my platinum members. Jasper says, I have been using a message box in my program to double check with the users before they delete a lot of data. The problem is if they hit a key by accident, the message box defaults to yes, which could cause important data to be erased. I tried to reword the message to make yes cancel the deletion, but it does not sound right. This will delete data. Would you like to cancel this request? It sounds dumb. Is there a way to simply change it so the default button is NO?

Why yes, of course Jasper. Let's take a look at how to do that.

Now, before we get started, if any of you have not used a message box before, go watch this. It will teach you how a message box works and how to get a reply from it. And of course, all of this is developer-level stuff, which means you will need to know a little VBA, but do not panic. VBA is pretty simple and, in fact, using a message box is really easy. Go watch my Intro to VBA video. It is about 20 minutes long. It will teach you everything you need to know to get started. It is on my website and on my YouTube channel. These are both free. Go watch them and come on back.

All right, Jasper. So to teach you how to do that, how to set the default button equal to NO, we have to learn a little bit more about the message box options.

Now, if you look at the message box function on Microsoft's website, you will see right down here it takes a bunch of parameters. All right, we have the prompt, which is the only one you really need, and then some optional ones: buttons, title. These are the only two we are going to worry about today. Then there is this help file stuff. Ignore the help file stuff for now.

All right, so the prompt you are all familiar with. It can be up to 1024 characters long, although you should never have a message box anywhere near that length. But you call it like this: Message box Picard is the greatest captain. Exclamation point. He is. No question about it. And you get this real simple message box as Microsoft Access with an OK button. So that is just to give someone a notice, let them know what is up.

All right, continuing on with that prompt definition. If it consists of more than one line, you can separate it using CHR 1013 or I like to use a VB new line. And you just do it like this. Right, Picard is the greatest captain. Dot, dot, dot, new line. And then right here, a VB new line character, which is a 1013 combination. And then you put ever and then your box looks like this. You can actually put lines in your message box. It all looks nice. And yes, you can put extra blank lines in there if you want to.

Now moving on to the buttons. There is a crazy definition with buttons and they all have weird values and all that stuff. But essentially, there are some button constants you are going to use to specify what buttons you want.

Here are the different button constants, the options you need to learn: VB OK only, which is just an OK button; OK, cancel; there is abort, retry, ignore. This goes back to the old days. Remember this? Abort, retry, ignore, those from like the DOS days.

Then we have yes, no, cancel. That is my favorite one. I like yes, no, and cancel, especially to prompt users for things where they could potentially damage stuff, like delete a lot of records. Because sometimes people get a message box, they are just yes to no, and they are not sure which one they want. What do I do? If you give them that cancel option, at least it lets them say, OK, back up. I do not know what I am doing. I do not want to answer yes or no. Just cancel what you are doing. So I always like to give them yes, no, and cancel.

OK, then you have just yes, no, and then retry, cancel. You do not have to worry about what these numbers mean. I will talk about them in just a minute. But all you need to worry about is this stuff, and you do not even really have to worry about remembering these, because when you go to create your message box, when you hit comma here after the prompt, you are going to get IntelliSense, and it is going to give you a big, long list of all the options. Just find the one you want, like OK, cancel. OK. And if you watch my other video, you have seen this in action, and we are going to do an example for the end of class.

All right, so here it is with OK, cancel after it. You get OK and Cancel. Now, having OK and Cancel buttons is meaningless if you cannot get that response from the user, which is what we talked about in the other video.

All right, so we can use a variable to get the value from message box. Now notice here you have to put parentheses around your message box, whereas before we did not need them. If you are just doing it so that you are just giving a message and you are not getting a response, you do not need the parentheses. But if you want to return the value, you need the parentheses here because now message box is acting as a function. It is going to return a value, and we are going to store it in response.

And yes, I know, before the technical people get on me, I know technically this returns an integer, but I always use long instead of integer. And there are reasons why, and I am not going to take the time to go into them now.

All right, but now we have yes and no, and we can actually get that value back. We will talk about that in a little bit, but we already did it in the other video.

All right, now in addition to just a plain Jane message box, you can also get cool little icons and sounds. Some of them make different sounds. There is critical, question, exclamation, and information. That is what they look like there. And personally, I pretty much only use question and then critical, because this one makes the big ball noise. And the question is like, hey, do you want to answer this for me? These two, yeah, you can use them. I do not often use these ones that much.

How do you specify those different ones? We add the values together. First you pick what buttons you want. Here I have just yes and no, and then you add to that the style that you want. Add critical, add question, add exclamation, and so on. Access will add those together internally. After you pick your button style, you hit the plus, and as soon as you hit plus, you will get your IntelliSense back again. And you can add those values.

Now, again, for the technical people, some trivia: what actually happens is those values get added together internally. So you get a unique combination of all the different button numbers. So for example, if you pick OK Cancel, that is one, and critical, that is sixteen, that adds up to seventeen, and Access knows there is only one possible way you can get the combination of seventeen and that is with those two buttons. So that is technically how it works.

Do you have to remember this? No. Do you have to use these numbers at all? No. Just giving you some trivia because sometimes it is cool to learn this stuff.

All right, now there is another option. There are a bunch of options, there are tons of options. Here is the default button option. It is second, third, fourth. So if we take yes, no, cancel, and add default button three, notice one, two, three, when the message box opens, notice this guy is the default button. So this should answer your question. If the message box pops up and the user accidentally hits the space bar, it is going to cancel. That is a great idea for something that is dangerous, like accidentally deleting records. Have cancel be your default.

Now this has come up a couple of times in the forums on my website over the last couple of years. But unfortunately there is not a no default button option. In other words, when that message box pops up, one of those buttons will be selected. So if the user hits space bar or enter, it is going to push a button. You want to make sure it is the safest option because there is no way to turn that off.

Now in my Access Developer 11 and 12 classes, I do show you how to build a project called the universal dialog box. It is this thing. You can specify the colors, the message, the title, what buttons appear, what the captions on the buttons are, whether or not there is a default button, all that, all those options. You control this form and it pops up as a modal form.

So if you want to learn how to do that, here is the link. I will put it down below, you can click on it, check it out.

But for those of you who have asked me over the last couple of years if there is a way to not have a default button, nope, sorry, cannot do it. Not with the built-in message box.

All right, now there are some options. If you look at the big long list on Microsoft's website, there are some options that no longer work. One of them is VB system modal. The default is application modal. It works just like a modal form. When that form pops up, you have to close that form before you can work on anything behind it. If you have a customer form and you want to open up the contacts, you cannot change the customer behind it. So message boxes normally work where they are modal. You cannot continue doing anything else in the database, working with forms, opening tables, that kind of stuff, until you answer that message box. You have to hit your OK or Cancel before anything else works.

Now back in the day, the old days, and I am not exactly sure how long ago this changed, I am going to guess it probably changed around Windows 7 or so. I do not know. I have to look it up. But in the old days, when Access first came out, it could do a system modal dialog box, which means that when Access popped up a message box, you had to answer it and you could not even switch to another application. You could not even switch over to Notepad or Excel. Access took control. New versions of Windows prevent one application from doing this. A single application cannot hijack the whole operating system now. So they have encapsulated that. But in the old days, you could do this. You cannot anymore. I am just full of trivia today. Benefit of being old.

Another option that does not work is the VB message box set foreground. This used to be cool back in the day. Again, if you have your database running in the background, like you opened it up and you have something that, like a timer event that runs or you have it so you can receive messages from other users on your network, well, if Access wanted to generate a message and pop up a message box, it could throw itself, the Access application, up as the foreground window. But nowadays, again, this option does not work. If Access is minimized or behind something else and you have your web browser up in front of it, it will not work. You will still see the taskbar icon change, but it cannot put itself in the foreground anymore.

So again, it is just another option that no longer works, but it is still in there.

There is another option called message box help button. We talked about this before with these different options where you can specify a help file. Now, I am not a big fan of help files. All right, HLP and CHM files. I do not like them. I might do a video on them in the future. They are kind of weird to put together. I do have my own help system option. I put this video together a couple of years ago to show you how you can build your own help system inside of Access, and I like doing it this way better. But unfortunately, this does not work with message boxes. You can make your own little help buttons and stuff or control the F1 key, but it does not work with the message box help button. But with this option, you can get a help button in your message box for the user. But it requires an HLP file. There, I fixed it, HLP.

Now, making these is a pain. Again, I might do a video on them in the future, but for now, just ignore that option.

For those of you with languages like Hebrew or Arabic, where it is right to left, there are some other options. There is VB message box right. You can use this if you want to, even if you are using English. It will just make the text align on the right side of the box.

All right, folks, that is going to do it for part one. We will see you on Monday for part two.
Quiz Q1. What is the main concern Jasper had with the default message box configuration in Access?
A. The message was too long for the message box
B. YES was set as the default button, increasing risk of accidental data deletion
C. The message box did not have enough buttons
D. The icons in the message box were confusing for users

Q2. What parameter in the message box function allows you to control which buttons appear (like OK, Cancel, Yes, No)?
A. Prompt
B. Buttons
C. Title
D. HelpFile

Q3. Which message box style is most appropriate when you want to give users the option to cancel a dangerous operation, like deleting records?
A. Abort, Retry, Ignore
B. Yes, No, Cancel
C. OK, Cancel
D. Retry, Cancel

Q4. How can you set which button is the default in a message box in VBA?
A. SelectDefaultButton
B. SetToNo
C. Add a default button constant to the button options
D. There is a default button property you set to True

Q5. What should you do if you want a message box to have multiline text?
A. Use semicolons to separate lines
B. Insert multiple message boxes
C. Use a new line character like VB new line or CHR 13
D. Only use a single line, multiline is not possible

Q6. What happens if a user presses Enter or Space when a message box appears?
A. The first button is always selected regardless of configuration
B. No button is triggered, and the message box stays open
C. The current default button is activated
D. The Cancel button is always selected

Q7. In Access VBA, if you want to capture the value of the button the user pressed on the message box, how should you structure your code?
A. Use message box without parentheses
B. Assign the message box function with parentheses to a variable
C. Use only the prompt parameter
D. Use the message box inside a For loop

Q8. What is the result of combining option constants, such as button styles and icon styles, by adding their values together?
A. The message box displays all options one at a time
B. The message box creates a unique combination of button and icon choices
C. The message box ignores additional options after the first one
D. The message box will error out

Q9. Which pair of icon options does the presenter say are most useful for message boxes?
A. Information and Exclamation
B. Critical and Question
C. Abort and Ignore
D. System and Foreground

Q10. Is it possible to create a message box with NO default button in built-in Access VBA?
A. Yes, by setting the default to None
B. Yes, but only with system modal option
C. No, one of the buttons must always be the default
D. Yes, with a custom API call

Q11. What is a modal form or message box in Access?
A. A form that cannot be closed
B. A form that restricts interaction with the rest of the application until closed
C. A form that is hidden from the user
D. A form that stays always on top of other Windows applications

Q12. What happens if you use VB system modal or VB message box set foreground options on modern Windows with Access message boxes?
A. They work as intended, forcing focus to the message box
B. They are recommended for compatibility
C. They no longer work as they did in old versions
D. They crash the Access application

Q13. How can you create a message box with more customizable features than the built-in MsgBox allows?
A. By using the VB system modal option
B. By using customized modal forms as shown in the Access Developer classes
C. By writing message box options in the registry
D. By editing the message box constants

Q14. Why does the presenter prefer using Long instead of Integer for the response variable from a message box in VBA?
A. Long supports larger numbers, though technically MsgBox returns an Integer
B. Long is required for text options
C. Integer is obsolete in VBA
D. Long returns the string version of a button pressed

Q15. Which of the following options allows text alignment to the right in a message box, useful for right-to-left languages?
A. VB message box right
B. VB system modal
C. VB critical
D. VB default button three

Answers: 1-B; 2-B; 3-B; 4-C; 5-C; 6-C; 7-B; 8-B; 9-B; 10-C; 11-B; 12-C; 13-B; 14-A; 15-A

DISCLAIMER: Quiz questions are AI generated. If you find any that are wrong, don't make sense, or aren't related to the video topic at hand, then please post a comment and let me know. Thanks.
Summary Today's TechHelp tutorial from Access Learning Zone focuses on the different options available when working with message boxes in Microsoft Access using VBA. My goal today is to help you understand how to configure message boxes with various buttons and icons, how to handle responses, and most importantly, how to make NO the default button instead of YES. This is a common request, especially when you want to prevent users from accidentally confirming a potentially destructive action.

Let me give you some context. Many developers use message boxes as a way to confirm user intentions before completing actions such as deleting important data. The concern Jasper brings up is that, by default, the YES button is often selected. So if the user accidentally hits the space bar or enter key, YES is selected and the deletion goes through, which can be dangerous. Rewording the message to make YES mean something else doesn't really solve the problem and can confuse users. What most people really want is to set NO, or even Cancel, as the default button so that if the user makes a mistake, the safest choice is selected.

Before we get too deep into this, if you're new to using message boxes, I strongly recommend watching my basic message box tutorial and my introduction to VBA. Those will explain the essentials of what a message box is, how to code it, and how to capture user responses. These resources will help you keep up with the examples I cover here.

In Access, the MsgBox function takes a few parameters. The key ones we'll focus on today are the prompt (the text message) and the buttons option. Prompt is the message you want to display and can be as long as 1,024 characters, though practically you should keep it much shorter for clarity. If you need multiple lines in your message, you can use special characters like VBNewLine to separate lines, which helps make long prompts more readable.

As for the buttons, Microsoft provides a number of built-in options, known as button constants, that let you control what buttons show up on the message box. You have choices like OK only, OK and Cancel, Abort/Retry/Ignore, Yes/No/Cancel, Yes/No, and Retry/Cancel. Personally, I'm a fan of using Yes/No/Cancel in situations where users could do something significant or potentially damaging, such as deleting a lot of records. Providing a Cancel option gives users a safe way out if they're not sure how to respond.

When setting up a message box, you don't have to remember all the exact constant names, because Access will show you the available options via IntelliSense as you type. So, after typing the prompt, you can specify which button combination you want, such as OK Cancel or Yes No Cancel, and Access will help you pick the right one.

Now, capturing the user's response is key. If you just want to display a message, you can use the MsgBox function without parentheses. But if you want to know what button the user clicked, you need to use parentheses and store the result in a variable. This returned value is typically an integer, but I usually use the Long data type for consistency and flexibility. The value tells you whether the user chose Yes, No, or Cancel, so you can program your response accordingly.

Icons can also be added to message boxes for emphasis or to help users quickly understand the context. Common options include Critical (red X), Question (question mark), Exclamation (yellow triangle), and Information (blue info icon). You set icons by adding their constant values to your button choice. For example, you might want a Yes/No question with the Critical icon, especially if you're prompting for something risky like deleting records. Access combines these values internally, but you don't need to memorize the numbers behind the constants; just use IntelliSense to select the options you want.

Now, here's the important part: setting the default button. By default, Access will select the first button listed - typically Yes in a Yes/No message box. However, you can use the DefaultButton constants to choose which button is selected. For instance, if you have Yes/No/Cancel, you can specify that Cancel should be the default by using the DefaultButton3 option. That way, if the user accidentally presses the space bar or enter, the safest choice is chosen. This is highly recommended for operations that could be risky.

However, let me clarify something that comes up frequently: there is no option to have no default button selected. One of the buttons will always be focused, so a keypress will always trigger a response. The best you can do is make sure the safest choice is the default.

For those interested in even more customization, such as creating a completely tailor-made dialog box with your own colors, captions, and logic, I teach how to build a universal dialog box in my advanced Access Developer classes. This is a modal form that gives you complete control, including defining your own defaults and responses. If you want maximum flexibility, you might want to explore that approach.

Now, a few more details about button options. Older versions of Access had a few features that are no longer supported, such as System Modal dialog boxes, which could prevent users from switching to other applications until the dialog was answered. Modern versions of Windows do not allow applications to take over the entire system like this anymore. The System Modal and SetForeground features are kept in the language for compatibility, but they no longer have any real effect.

There's also an option to include a Help button, but it requires you to have a classic Windows help file (HLP or CHM format), which is not commonly used nowadays. If you want to provide help, I recommend building your own integrated help system within Access, which is a topic I cover in a separate video.

Lastly, for users working with right-to-left languages, there are options to align the message box text to the right. You can use the MessageBoxRight constant for this purpose, even if you simply prefer right alignment.

That covers the essentials for part one of this tutorial on message box options. If you want a more complete, step-by-step walkthrough including specific code examples and demonstrations, you can find the video tutorial on my website at the link below.

Live long and prosper, my friends.
Topic List Message box function parameters in VBA
Prompt parameter and multi-line messages
Button constants and their usage
Options for button combinations in message boxes
Using message box to capture user responses
Adding icons to message boxes
Combining button and icon options
Setting the default button in message boxes
How message boxes handle modal windows
Obsolete message box options explained
The help button option in message boxes
Right-to-left text alignment in message boxes
 
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 4/21/2026 12:59:58 AM. PLT: 1s
Keywords: TechHelp Access 2016, Access 2019, Access 2021, Access 365, Microsoft Access, MS Access, MS Access Tutorial, #msaccess, #microsoftaccess, #help, #howto, #tutorial, #learn, #lesson, #training, #database, Set No as Default, Customize MsgBox, Change Default   PermaLink  MsgBox Options in Microsoft Access