MsgBox Code Samples

Tuesday, March 26, 2002 19:41:24
home



Sample#1--Customized Heading, Non-Interactive

msgbox

The example shown below shows a simple message box, but the HEADING appearing in the 'title-bar' portion of the message box says Permissions Violation, rather than the Microsoft Access name (or the name of the database itself), which is the default behavior.

MsgBox "You Don't Have Permission to Modify the Contents of this Record; " _
& "You Weren't The One Who Created it.", , "Permissions Violation"

Notice the 2 commas near the end of the line. Also, of course, this one was broken into two lines. That's done by adding a space and _ to the end of the 1st line, and concatenating at the beginning of the 2nd line.


Sample 2:Yes/No Message Box, Customized Heading

Yes/No Message Box

In this example, the user is prompted to answer YES or NO, and different code executes depending on whether the user clicks YES or NO.

Dim response As Integer, message As String
message = "Are you sure you wish to change the type of case; doing so may erase vital data"
response = MsgBox(message, vbYesNo, "Warning! From Larry...")
If response = vbNo Then
' Enter the code here you wish to execute if the user clicks NO
End If