Contents in short
- Improvement / Replacement / better VBA msgbox
- Works on MS Access 2019/2016/2013/2010/2007 for 32bit and 64bit
- Creative Commons Attribution License 3, MS Access VBA, accdb
Improved, Enhanced Message Box Replacement for MS Access
This project provides a custom and enhanced message box replacement for the default MsgBox found in Access.
A accdb demo database with a Your-Code-Wizard containing all the code for Access 2007/2010/2013/2016/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 demodatabase 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.
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)!
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!
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".
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.
Your-Code-Wizard from one of the dialog boxes above - ready to copy&paste! No need to code anything by hand.
'Your-Code-Wizard by https://www.datenbank-projekt.de strResult = Dialog.RichBox(Prompt:= "<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?" & "", _ Buttons:=(1024+64), _ Title:="Enhanced Message Box", _ LabelButton1:="Button1", _ LabelButton2:="thisDefault", _ LabelButton3:="Button3", _ DismissID:="", _ AutoCloseSec:=3, _ DefaultButton:=2, _ BGColorButton1:= RGB(200,200,225), _ BGColorButton2:= RGB(100,225,100), _ BGColorButton3:= RGB(225,100,100), _ AllowBeep:=True, _ AllowCopyToClipboard:=True, _ AllowSaveToFile:=True, _ ButtonDelay:=2, _ NoStrEsc:=False)
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:
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 labled 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).
Suggestions? Questions? Wishes?
Please let me know using the contact form.
- 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