ACC2000: MsgBox Function Ignores At Sign (@) Formatting (242889)



The information in this article applies to:

  • Microsoft Access 2000

This article was previously published under Q242889
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

SYMPTOMS

In Microsoft Access 2000, the at sign (@) does not provide special formatting when you use it with the MsgBox function.

CAUSE

The MsgBox function provided by the Microsoft Visual Basic Editor (Vbe6.dll) does not support the formatting provided by the at sign (@).

RESOLUTION

There are two possible solutions. One solution is to use the MsgBox action in a macro. The other solution is to write a user-defined function that uses the Eval function to call the MsgBox function.

Creating a Macro that Uses the MsgBox Action

  1. In the Database window, click Macros under Objects, and then click New.
  2. In the Macro window, click the arrow under Action, and then click Msgbox in the Action list.
  3. Press F6 to move the pointer to the Message box under Action Arguments.
  4. Type the following message in the Message box:

    Wrong button!@This button doesn't work.@Try another.

  5. On the File menu, click Save As, and then click OK to save the macro with the default name.
  6. On the Run menu, click Run. Note that the first line of the message is bold.

Creating the FormattedMsgBox Function

The Eval function forces the Visual Basic for Applications expression service to evaluate the MsgBox function separately from Visual Basic Editor, and therefore it is possible to take advantage of at sign formatting. The following example uses a user-defined function named FormattedMsgBox instead of the MsgBox function. To create the FormattedMsgBox function, follow these steps:
  1. Start Microsoft Access.
  2. Open the sample database Northwind.mdb.
  3. Create a new module.
  4. Add the following procedure to the module:
    Function FormattedMsgBox(Prompt As String, _
                             Optional Buttons As VbMsgBoxStyle = vbOKOnly, _
                             Optional Title As String = "Microsoft Access", _
                             Optional HelpFile As Variant, _
                             Optional Context As Variant) As VbMsgBoxResult
        Dim strMsg As String
        If IsMissing(HelpFile) Or IsMissing(Context) Then
           strMsg = "MsgBox(" & Chr(34) & Prompt & Chr(34) & ", " & Buttons & _
                     ", " & Chr(34) & Title & Chr(34) & ")"
        Else
           strMsg = "MsgBox(" & Chr(34) & Prompt & Chr(34) & ", " & Buttons & _
                     ", " & Chr(34) & Title & Chr(34) & ", " & Chr(34) & _
                          HelpFile & Chr(34) & ", " & Context & ")"
        End If
        FormattedMsgBox = Eval(strMsg)
    End Function
    					
  5. Save the module by using the default name that appears in the Module Name box.
  6. When you want to use the special formatting provided by the at sign, call the FormattedMsgBox function instead of the built-in MsgBox function. For example:
    Sub TestMsgBox()
        Dim lngResult As Long
        lngResult = FormattedMsgBox("Extremely Important@This is an invalid operation.@Refer to online help.", _
            vbCritical + vbOkOnly, "Microsoft Access")
    End Sub
    					

MORE INFORMATION

In earlier versions of Microsoft Access, you can use the at sign to format portions of the message text in a MsgBox function. When you use two at signs in the text of the MsgBox function, the text delimited by the at sign is separated into three paragraphs in the Message Box, with the first paragraph in bold text.

This functionality is provided by the Visual Basic for Applications library (Vba332.dll) in Microsoft Access 97. With the integration of the Microsoft Visual Basic Editor, Microsoft Access 2000 no longer implements Vba332.dll.

Steps to Reproduce Behavior

  1. Start Microsoft Access.
  2. Open the sample database Northwind.mdb.
  3. Create a new module.
  4. Add the following code to the module:
    Option Compare Database
    Option Explicit
    
    Sub FormatMessage()
        Dim strMsgText As String
        strMsgText = "Extremely Important@This is an invalid operation.@" & _
                     "Refer to online help."
        MsgBox strMsgText
    End Sub
    					
  5. Run this procedure in the Immediate window.
Note that the message contains the literal string "Extremely Important@This is an invalid operation.@Refer to online help." In Microsoft Access 95 and 97, this message is formatted into three separate paragraphs with the text "Extremely Important" in bold, similar to the following:

Extremely Important

This is an invalid operation.

Refer to online help.


Modification Type:MajorLast Reviewed:6/24/2004
Keywords:kbprb KB242889