In Access 97, the MsgBox function had a documented syntax for creating formatted message boxes by use of the @ sign, and it would
use the Office Assistant if the Assistant was turned on. For example, you could use the following from Access 97 help. For example, this line
Msgbox "Bold Line@Plain Line@Another Plain Line", _
vbInformation+vbOKOnly, _
"Formatting sample"
produces the first line in bold.
In Access 2000 (which integrates VBE, the Visual Basic Editor), the VBA MsgBox function does not call back into Access to do this work, so you lose formatted message boxes and you also lose the ability to have the Office Assistant "front" for your messages. But there is a workaround!
By using the Eval function, your call will go through the Expression Service that interfaces with Access and Jet to run the MsgBox function, and it will call into the Access version instead of the VBA version. So you can add the following to your Access database and call it instead of the VBA MsgBox to get back the 97 functionality:
Function FormattedMsgBox( _
Prompt As String, _
Optional Buttons As VbMsgBoxStyle = vbOKOnly, _
Optional Title As String = vbNullString, _
Optional HelpFile As Variant, _
Optional Context As Variant) _
As VbMsgBoxResult
If IsMissing(HelpFile) Or IsMissing(Context) Then
FormattedMsgBox = Eval("MsgBox(""" & Prompt & _
""", " & Buttons & ", """ & Title & """)")
Else
FormattedMsgBox = Eval("MsgBox(""" & Prompt & _
""", " & Buttons & ", """ & Title & """, """ & _
HelpFile & """, " & Context & ")")
End If
End Function
Another option if your application relies heavily on this type of formatting,
would be to
use a form in place of the MsgBox dialog and roll your own replacement for the MsgBox
function. One such example is provided by Arvin Meyer.
|
Data
Strategies
(Look under the Downloads section for Custom MsgBox Creator.) |
|