Home

The Message Box

 

Introduction

 

A message box is a Windows(operating system)-created form used to display some information to the user. As opposed to a regular form, the user cannot type anything on the box. There are usually two ways you can use a message box: you can simply display a message to, or request an answer from, the user.

To create a message box, you use a function called MsgBox. If you only want to display a message, the syntax you would use is:

MsgBox(Message To Display)

This function takes only one required argument, the message to display, that you must pass in the parentheses of the function. The message can be passed between double-quotes.

To display a message to the user, place a command-based control, such as a Button, to a form. Then, access the Properties window for the control. In the Events tab of the Properties, click On Click and assign the function to the field. An example would be:

=MsgBox("Remember to submit your time sheet")

When the user clicks the button, a message box would come up:

If you want to display the message box on various lines, edit the string to include a call to Chr(10). Here is an example:

MsgBox("Remember to submit your time sheet" + Chr(10) 
       "Only time sheets received on time will be honored", )

This would produce:

The message to display can also come from another control on the form. For example, you can retrieve the value of a control and pass it as argument to the MsgBox() function.

The simplest message box displays only a message to the user, with one button marked OK. If you want, you can display more than one button on the message box. To support this, you can bed the following syntax of the MsgBox() function:

MsgBox(Message to display, Options)

The second argument allows you to specify the button(s) to display. To do this, pass a constant integer as argument from the following table:

Value Buttons
0
1
2
3
4
5

Here is an example:

=MsgBox("Do you want to submit your time sheet?",4)

This would produce:

If you provide a value other than those in the list, the message box would display only the OK button.

Besides displaying a button, the second argument is also used to display an icon. To get an icon, you add one of the following values:

Value Icon Suited when
16 Warning Warning the user of an action performed on the database
32 Asking a question that expects a Yes or No, or a Yes, No, or Cancel answer
48 Exclamation A critical situation or error has occurred. This icon is appropriate when informing the user of a termination or deniability of an action
64 Information Informing the user of a non-critical situation

To use one of these icons, add (a simple addition) its value to that of the desired button or combination of buttons from the previous table. Here is an example created with

=MsgBox("Do you want to submit your time sheet?", 4 + 32)

This is the same as:

=MsgBox("Do you want to submit your time sheet?", 4 + 32)

This would produce:

When the buttons of a message box display, if the message box has more than one button, one of them has a thick border. This button is referred to as the default button. If the user presses Enter, such a button would be activated. Besides selecting the buttons and displaying an icon, the second argument can also be used to specify what button would have focus, that is, which one would have a thick border and would be applied if the user presses Enter. The default button is specified using one of the following values:

Value If the message box has more than one button, the default button would be
0 The first button
256 The second button
512 The third button
768 The fourth button

To specify this option, add the number to the second argument.

When a message box comes up, it displays a title as Microsoft Office Access. If you want, you can specify your own title. To support this, you can pass a third argument to the MsgBox() function. This third argument is referred to as the caption. The syntax to use is:

MsgBox(Message to display, Options, Caption)

Pass the third argument as a string, for example in double-quotes. Here is an example:

=MsgBox("Do you want to submit your time sheet?",
	4 + 64,
	"Georgetown Dry Cleaner")

This would produce:

Because MsgBox is a function, you can retrieve the value it returns and use it as you see fit. The value this function returns corresponds to the button the user clicked on the message box. Depending on the buttons the message box is displaying, after the user has clicked, the MsgBox() function can return one of the following values:

If the button(s) displayed was(were) And if the user clicked The MsgBox() function returned
1
1
2
3
4
5
6
7
2
6
7
4
2
 

Home Copyright © 2008-2016, FunctionX, Inc.