Microsoft KB Archive/242889

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

Article ID: 242889

Article Last Modified on 6/24/2004

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



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
 In the Database window, click Macros under Objects, and then click New. In the Macro window, click the arrow under Action, and then click Msgbox in the Action list. Press F6 to move the pointer to the Message box under Action Arguments. Type the following message in the Message box:

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

 On the File menu, click Save As, and then click OK to save the macro with the default name. On the Run menu, click Run. Note that the first line of the message is bold.</li></ol>

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: <ol> Start Microsoft Access.</li> Open the sample database Northwind.mdb.</li> Create a new module.</li>  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 </li> Save the module by using the default name that appears in the Module Name box.</li>  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 </li></ol>

<div class="moreinformation_section">

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
<ol> Start Microsoft Access.</li> Open the sample database Northwind.mdb.</li> Create a new module.</li>  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 </li> Run this procedure in the Immediate window.</li></ol>

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.

Additional query words: prb

Keywords: kbprb KB242889

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.