Chinese - Simplified   Dutch   English - United States   French   German   Portuguese - Iberian   Spanish  

Home




Usenet Posting #15 - Trigeminal Software, Inc. (English)


Subject: INFO: The formatted MsgBox in Access 2000
(Originally posted 9/30/99)
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):

MsgBox "Wrong button!@This button doesn't work.@Try another.", _

   vbOKOnly + vbExclamation

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

Here is the difference. I'll let you decide which one you like better:

VBE MsgBox
           MsgBox "Wrong button!@This button doesn't work.@Try Another.", 
           vbOKOnly + vbExclamation, "My Application"
      
Formatted MsgBox
           FormattedMsgBox "Wrong button!@This button doesn't work.@Try Another.", 
           vbOKOnly + vbExclamation, "My Application"
      

Back to Usenet Musings


Problems with this site? Please contact the webmaster@trigeminal.com
with your comments, questions, or suggestions.