datenbank-projekt.de

Improved, Enhanced Message Box

Message Box Replacement for MS Access

(and VBA. Free)

Donate with PayPal

Contents in short
  • Improvement / Replacement / better VBA msgbox 
  • Works on MS Access 365/2019/2016/2013/2010/2007 for 32bit and 64bit
  • Creative Commons Attribution License 3, MS Access VBA, accdb

ContactDownload at the bottom of the page

This project provides a custom and enhanced message box replacement for the default MsgBox found in Access.

A free ACCDB database with a Your-Code-Wizard containing all the code for Access 2007/2010/2013/2016/365(2019) for 32bit and 64bit is available below!

This is not a tool I created myself, but I put quite some work into improving it. I tried to contact the original developer Renaud Bompuis and made the update available to him, but I also wanted to make sure it's available from here.

Renaud explains very good how easy it is to replace the original msgbox with his dialog.box or dialog.richbox - the latter displaying Access richt text format.

The improvements I made over his original 1.10 version are documented at the bottom of this page in detail. 

You can download the database in accdb format here. If you change anything, especially improve the code, please send me an update. Also make sure to leave credits and links to Renauds and my page in the code.

Installation

You need to grab all files from the file you download and copy them into your own application (there is another module in the demo database - compared to Renaud's version)!

Features

So let's see what the improved version can do for you. In the first picture you see the base form of the tool. I redesigned it a little to make room for the features which include:

  • Page Your Code Button where the Your-Code-Wizard generates code for the button you just created, so that you can Copy&Paste it directly into your modules! This means, the original form not only works as a demo, but also helps you to create beautiful buttons even with rich text (RTF) messages!
  • Custom Default Button: It seemed a good idea to me not always to use the standard default button (opened dropdown in image) but to make it cusomizeable! You can decide which of the three buttons should be the default button.
  • The new default button feature goes along with the AutoCloseSec option: After the buttons are being enabled the AutoCloseSec options starts a countdown with the length of the value of this option. Once the countdown is down to zero, the dialogbox (messagebox) will close automatically, returning the/your default button!
  • The Avoid Long Wizard-Text-Code checkbox helps you, in case the Your-Code-Wizard has too many linebreaks (too many for VBA). Just enable the checkbox and your messagetext will be created in a single line so that there should be no problems copying the Your-Code-Wizard code to your own VBA module.
  • Custom Buttons are nice, but custom color buttons are nicer! Look at the screenshots below as well: You can easily set a color for each of the buttons (even if not vbCustom)! Simply enter RGB values and you are done. The buttons now have a hand symbol when you hover them and they get a hover effect!
  • In version 1.21 I added the option to make the enhanced message box modal - or not. Until then, it was always modal. Being not modal will allow the user to continue his work even when the box is open and allow your code to execute in different places.
  • Do I need to mention, that the standard MsgBox buttons will not create some Your-Code-Wizard code?
  • Also: Everything Renaud writes in his blog about his tool concerning implementing it in your own project is still true: You can run a search (msgbox) and replace (with dialog.box)! You can also still run a correct msgbox "my test message",vbOKOnly,"This is the title" as dialog.box "my test message",vbOKOnly,"This is the title" - no need to use the Your-Code-Wizard! 

Enhanced Message Box Wizard

This is what the buttons can look like now. First image shows button 1 to be the (system)default, the second image shows the middle button (button 2) to be the (custom) default. In both images you can see the number in brackets (3) and (2) - which are the AutoCloseSeconds remaining before the specific button will be "pressed".

Example Enhanced Message Box

Example Enhanced Message Box

In the upper part of the next image you see the Your Button Code page open, showing the code that can be copied and pasted into your application! A little side note: The code might look ugly in this preview, but looks very nice in your code window! You can see the wizard created code below this image.

Preview Code Wizard

Your-Code-Wizard from one of the dialog boxes above - ready to copy&paste! No need to code anything by hand.

Use keyboard shortcuts as usual

You can use the ampersand (&) symbol before characters in the button description to enable keyboard access as usual:

Ampersand symbol to enable keyboard access to buttons

'Your-Code-Wizard by https://datenbank-projekt.de
'create 2 variables in your code: strMessage as string and strResult as string!

strMessage = "<div><font size=3 color=""#808080""><strong>Too late for boarding</strong></font></div><p/>You flight <font face=Consolas style=""background-color:#FFFF00"">BA5584</font> has already left the runway.<br/>It 's a bit too late to run after it.<p/><p/>Would you like to book another flight?"

strResult = Dialog.RichBox(Prompt:= strMessage, _ 
	Buttons:=(1024+64), _ 
	Title:="Enhanced Message Box", _ 
	LabelButton1:="&Button 1", _ 
	LabelButton2:="Bu&tton 2", _ 
	LabelButton3:="Button &3", _ 
	DismissID:="", _ 
	AutoCloseSec:=10, _ 
	DefaultButton:=0, _ 
	BGColorButton1:= RGB(255,0,255), _ 
	BGColorButton2:= RGB(255,255,0), _ 
	BGColorButton3:= RGB(255,0,0), _ 
	BoxIsModal:=False, _ 
	BoxIsOnTop:=True, _ 
	AllowBeep:=True, _ 
	AllowCopyToClipboard:=True, _ 
	AllowSaveToFile:=True, _ 
	ButtonDelay:=2, _ 
	NoStrEsc:=False, _ 
	AcceptNotice_Text:="", _ 
	AcceptNotice_Option:=1, _ 
	DelayShow_Countdown:=False)

The code above was generated by a simple click on the "Enhanced RichBox  (creates 'Your code button')"-button and essentially produces this Dialog.Box:

EnhancedMsgBox example

Hints, tips and tricks

Sometimes things just won't work as you expect. There are several workarounds which might help you.

  • If the resulting message box is not wide enough, try to add some spaces at the end of your text.
  • If the resulting message box is not high enough, try to add some \n (new line markers) below your text and make sure the checkbox "Keep text raw (NoStrEsc)" is unchecked.
  • Of course: You need to import both forms and modules into your own application.
  • Currently, if you display a hyperlink, you will not be able to click on it! The Access RTF editor will format the hyperlink to look like one, but clicking will not work. This makes a lot of sense, as all text is contained in a textbox and this textbox does a) not have a hyperlink target assigned and b) there could be more than one hyperlink anyways in your text. So - where should a click send the user to?
  • If you get a "too many line continuation error" (happens sometimes even if you have checked the "Avoid Long Wizard-Text-Code"), I suggest a simple solution. Place all the generated text that should be displayed into a variable and simply display the variable instead of direct text in the dialog.box. Many times I use this as it's likely to have changing data anyways and thus preparing a string seems a better way to me. Please see the auto generated code above for an example (which was created by an unpublished version of the tool).

Note for non-unicode users (Arabic, Chinese, Indian languages etc.)

Please note, that this first idea may actually not work. I suggest you try the second idea first to get the improved enhanced message box working for non-unicode languages.

Second non-unicode idea

To solve: Instead of writing the Urdu (non-unicode) message in VBE, store it in a table and then call related text message when required.

First non-unicode idea (may not work)

I was notified, that an older version (1.18) did throw an error when the user started the tool. This error looked like this:

OLE Error Message

It turned out, that actually the VBA editor is not capable of using unicode (in simple words) but the user mentioned, that he is working on a system with regional settings set to Arabic (Saudi-Arabia). We tried and found a/the solution how you can make the software work on your system.

To reproduce, please visit and copy some Urdu (non-unicode) text from e.g. www.urdupoint.com (a website in Urdu language), use it in frmEnhancedMessageTest to generate the code (and view the message box demo) and then use the same code into any button click event on the same form. You will see that demo works fine but click event code message box strange.

To solve, please open the regional settings on your windows using Windows-Key + R to open the execute window. Type intl.cpl and press the Enter-Key. You will see a window where, on the right register (Administrative) you can change some regional settings. Click there the button in the lower part of the window that reads Change system locale. In the following window, check the checkbox that is labeled like Beta: Use Unicode UTF-8 for worldwide language support. Doing this should enable you to use the application (after your system has been restarted).

Suggested (possible) solution

Download and Donate with PayPal

Similar tools

Similar tools are the Attention Seeking Database and the Formatted Message Box, both from Colin Riddington.

Suggestions? Questions? Wishes?

Please let me know using the contact form.

Updates I made from the original 1.10 version

  • version 1.24
    • added color and text to the preview buttons
    • added show countdown for enable delay
    • added strMessage to hold textfield contents
    • added check for ESC key in dialog. This used to close the form with the System-Default button. We do not want to close without a real button pressed
    • corrected return value from GetSystemResourceString (now only actual length)
    • corrected setting of OtherOptions on FormLoad -> SetDefaultOtherOptions is called
    • added links on my website to similar tools from Colin
  • version 1.23
    • updated btCopy_Click to prevent error 2046 when copying (some machines, depending on access settings of the user).
  • version 1.22, 1.22b, 1.22c
    • reset the dialog window to pop-up
    • reset calculation of screen positon to method before 1.21
    • little error handling improvement
  • version 1.21
    • added checkbox to make enhanced message box modal or not
  • version 1.20
    • made changes to use windows non-unicode regional settings (thanks Abid)
  • version 1.18
    • added ButtonDelay to wizard output
  • version 1.16
    • corrected richbox default bgcolor of buttons
  • version 1.15
    • added custom default button option
    • added box title
    • added Your Button Code / Code-Wizard page for easy copy&paste
    • made UnEscStr public function to be used in form as well
    • added test if default button is visible, if not set new default button
    • added backgroundcolor option for each button
    • added hover effect for buttons
  • version 1.13, 1.14
    • added AutoCloseOption with countdown on default button
  • version 1.12b
    • made tool working on access 32 and 64 bit
    • added IsBlankEMB to script for testing of empty/null variables