The syntax is messy so I use a function to make it simpler to work with
Place this in a standard module:
Code:
Public 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
On Error GoTo Err_Handler
'Taken from http://www.trigeminal.com/usenet/usenet015.asp
If IsMissing(HelpFile) Or IsMissing(Context) Then
'NOTE: I NEVER use this section - it could be omitted
FormattedMsgBox = Eval("MsgBox(""" & Prompt & _
""", " & Buttons & ", """ & title & """)")
Else
FormattedMsgBox = Eval("MsgBox(""" & Prompt & _
""", " & Buttons & ", """ & title & """, """ & _
HelpFile & """, " & Context & ")")
End If
'Examples:
'section before @@ is in BOLD followed by blank line
'strPrompt = "Import completed@@" & strPrompt
'FormattedMsgBox strPrompt, vbInformation + vbOKOnly, "Contact import completed"
'FormattedMsgBox "Bold text here!@First line normal text.@Second line normal text.",vbOKOnly + vbExclamation, "Box Title"
Exit_Handler:
Exit Function
Err_Handler:
'various obscure errors which you may never experience
If err = 5 Or err = 13 Or err = 94 Or err = 2465 Then Exit Function
strProc = "FormattedMsgBox"
MsgBox "Error " & err.Number & " in " & strProc & " procedure : " & vbCrLf & " - " & err.description
Resume Exit_Handler
End Function
Then in the immediate window type this to get the message box I showed before:
FormattedMsgBox "Bold text for important text here!" & _
"@First line normal text. " vbCrLf & _vbCrLf & _
"Second line normal text. @",vbOKOnly + vbExclamation, "Formatted Message Box Title"
One other nice thing about it is that you can widen the formatted message box by leaving deliberate spaces at the end of lines.
That doesn't work in a standard message box
For customised message boxes (and other ways of getting user's attention), see this example database: https://www.accessforums.net/showthread.php?t=69858