Using the Msg Box Function

The MsgBox function you have used so far was limited to displaying a message to the user in a simple, one-button dialog box. You closed the message box by clicking the OK button or pressing the Enter key. You create a simple message box by following the MsgBox function name with the text enclosed in quotation marks. In other words, to display the message "The procedure is complete." you should prepare the following statement:

MsgBox "The procedure is complete."

Part I

You can try out the above instruction by entering it in the Immediate window. When you type this instruction and press Enter, Visual Basic displays the message box shown in Figure 4-1.

Figure 4-1: To display a message to the user, place the text as the argument of the MsgBox function.

Microsoft Office Access |_X |

Microsoft Office Access |_X |

The MsgBox function allows you to use other arguments that make it possible to determine the number of buttons that should be available in the message box or to change the title of the message box from the default. You can also assign your own help topic. The syntax of the MsgBox function is shown below.

MsgBox (prompt [, buttons] [, title], [, helpfile, context])

Notice that while the MsgBox function has five arguments, only the first one, prompt, is required. The arguments listed in square brackets are optional.

When you enter a long text string for the prompt argument, Visual Basic decides how to break the text so it fits the message box. Let's do some exercises in the Immediate window to learn various text formatting techniques.

0 0

Post a comment