Code Samples for Businesses, Schools & Developers

First Published 3 July 2017                 Last Updated 28 Oct 2023

FormattedMsgBox1
The following code allows bold text in a standard message box as well as standard features such as message box icons and more than one button.
You can also include context help items though I've never done so

The code uses the Eval function to format the first part of the code in BOLD text

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

'Originally from http://www.trigeminal.com/usenet/usenet015.asp (now defunct)

       FormattedMsgBox = Eval("MsgBox(""" & Prompt & """, " & Buttons & ", """ & title & """)")

Exit_Handler:
   Exit Function

Err_Handler:
   MsgBox "Error " & Err.Number & " in FormattedMsgBox procedure : " & vbCrLf & "   - " & Err.Description
   Resume Exit_Handler

End Function


For example:

FormattedMsgBox "You are not currently connected to the Internet     " & _
                   "@Location map data cannot be downloaded  " & vbCrLf & vbCrLf & _
                   "Please try again later       @", vbCritical, "No Internet connection"



FormattedMsgBox2

Functions can also be included in the message box text.

In this example, it is being used with a function GetLatestWebVersion:


FormattedMsgBox "Currency Exchange Rates Tracker version " & GetLatestWebVersion () & " is now available for download       " & vbCrLf & _
                   "from the Mendip Data Systems website           " & _
                   "@Click YES to close the program and download the latest version now          " & vbCrLf & _
                   "Click NO if you want to download this later          @", _
                       vbExclamation + vbYesNo, "New version available"



FormattedMsgBox3
Formatted message boxes are particularly useful for displaying error messages and allow more control over the width of the message.
For example:

FormattedMsgBox4
The formatted message box is included as one method of getting users' attention in my example Attention Seeking database.

The example app also includes other types of message such as customised message boxes and task dialog messages.



UPDATE: 29 Jan 2023

Handling Other Languages

Whilst working on my Access Application Translator utility, I discovered another advantage of the formatted message box.

Unlike standard message boxes, it can handle text in languages that use Unicode character sets such as Japanese, Greek, Bengali etc without needing to change locale or keyboard settings. This includes right-to left languages such as Arabic and Hebrew.

English

FormattedMsgBoxEn

Arabic

FormattedMsgBoxArabic

Chinese (Traditional)

FormattedMsgBoxChinese

By contrast, the standard message box only works with Latin script languages such as English, German, Spanish etc.
It cannot handle languages which use Unicode character sets such as Arabic or Bengali unless additional changes are made to locale and keyboard settings

English

StandardMsgBoxEn

German

StandardMsgBoxDe

Bengali

StandardMsgBoxBn

NOTE:
1.   The language used for the message box buttons is updated automatically when the default Office language is changed

2.   I have also created a Unicode Input Box function for use with unicode character sets such as Arabic, Japanese etc



UPDATE 28 Oct 2023

If you want even more customisation in your messages, consider using one or more of the following:
1.   Enhanced Message Box - this allows the use of rich text in message boxes together with other enhancements. See Improved Enhanced Message Box
      This was a project originally by Renaud Bompuis (Cyprus) and more recently further improved by Olaf Nohring.

2.   Task Dialog Messages - in addition to rich text, this allows even more variations including the use of hyperlinks, timers, more buttons etc.
      See Task Dialog Messages. This project was based on VB6 code by fafalone and further developed by Kevin Bell.

3.   Customised Message Forms - for complete customisation, create your own message forms which can have any feature you require.
      There are various examples included as part of my Attention Seeking example database elsewhere on this website.



Feedback

Please use the contact form below to let me know whether you found this article interesting/useful or if you have any questions/comments.

Please also consider making a donation towards the costs of maintaining this website. Thank you



Colin Riddington             Mendip Data Systems            Last Updated 28 Oct 2023



Return to Code Samples Page




Return to Top