Displaying and Responding to Messages

When you want your database to give the user a little feedback or have the user answer a simple Yes/No question, you can use a message box. The message box can be a simple feedback message with a single OK button, like the example shown at the left side of Figure 9-1. Or, the message box can ask a question and wait for an answer, as in the right side of Figure 9-1.

Figure 9-1:

Examples of message boxes.

Figure 9-1:

Examples of message boxes.

There are two syntaxes for the MsgBox keyword. If you just want the message to show some text and an OK button, use the syntax

MsgBox "YourMessageHere"

where YourMessageHere is the text that you want the message box to display. For example, here's the complete VBA code to display the message on the left side of Figure 9-1:

MsgBox "Finished exporting records"

If you type that exact statement into the VBA Editor Immediate window and press Enter, you'll see the message box onscreen. When you click its OK button, the message box closes.

The preceding syntax, where you just follow the MsgBox statement with a message enclosed in quotation marks, works only when you don't specify buttons to display in the message box. The message box will have only an OK button, and clicking that button closes the message box.

If you want your message box to ask a question and give the user some choices as to how to respond, you have to use a different syntax, as discussed next.

Was this article helpful?

0 0

Post a comment