473,396 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,396 developers and data experts.

'Spruce Up' Your Message Boxes!

ADezii
8,834 Expert 8TB
Have you ever wondered how Microsoft Access displays those Custom Message Boxes with the first line in BOLD, and the second and/or second and third lines in Normal Font Weight? The answer lies in the unique ability to break up your Message Text into either two or three Paragraphs using the "@" symbol, then evaluating the entire expression using the Eval() Function.

The "@" symbol inserted into your Message Text will break the Message into Paragraphs, with the Text before the first "@" shown in BOLD. Subsequent Paragraphs (you are limited to three) must be followed by the "@" symbol. If you only want to break for two Paragraphs, you must use two "@" symbols at the end of the second Paragraph. Simply download the Attachment to actually see how this is accomplished. The Attached Code can also be used as a Template for your future 'Spruced Up' Message Boxes!

Special Considerations:
  1. You cannot use Variables in your Message Boxes with this Method.
  2. You cannot use the VB Intrinsic Constants such as vbOKCancel, these Constants must be given as specific numbers which you can readily reference in the Help Files or Object Browser.
Expand|Select|Wrap|Line Numbers
  1. 'Code for 2 Paragraphs with OK, Cancel Buttons and an Information Icon, Default Button = 1 [OK]
  2. '(notice the double "@@")
  3.     'vbOKCancel = 1
  4.     'vbInformation = 64
  5.     'TOTAL Constant Value = 65
  6. If Eval("Msgbox('Paragraph 1/Line 1 - this Line will be in BOLD!@Paragraph 2/Line 2 - Click ""OK"" " & _
  7.         "to confirm your Delete or ""Cancel"" to UNDO your deletion.@@',65, 'Message Box Title')") = vbOK Then
  8.   MsgBox "You chose OK!"
  9. Else
  10.   MsgBox "You Canceled the previous Operation!"
  11. End If
  12.  
  13. 'Code for 3 Paragraphs with Abort, Retry, Ignore Buttons and an Exclamation Icon
  14. 'Default Button = 2 [Retry], (each Paragraph separated by "@")
  15.     'vbAbortRetryIgnore = 2
  16.     'vbExclamation = 48
  17.     'vbDefaultButton2 = 256
  18.     'TOTAL Constant Value = 306
  19. Select Case Eval("Msgbox('Paragraph 1/Line 1 - this Line will be in BOLD!@Paragraph 2/Line 2 - Normal Text.@" & _
  20.                  "Paragraph 3/Line 3 - Normal Text.@',306, " & _
  21.                  "'Message Box Title')")
  22.   Case vbAbort
  23.     MsgBox "You Aborted the previous Operation!"
  24.   Case vbRetry
  25.     MsgBox "Way to go! Let's give it another try!"
  26.   Case vbIgnore
  27.     MsgBox "You chose to Ignore the previous Operation!"
  28. End Select
Apr 29 '08 #1
8 12331
Johar
1
Thank you for this insightful article. Based on your information I wrote a quick function, that almost replaces the normal messagebox (works in Access 2007 - older versions may not be able to understand the optional-parameter; just remove the optional keywords and the IfMissing-codelines.

Here is the code. Simply put it in a standard code module and enjoy.
Expand|Select|Wrap|Line Numbers
  1. Public Function BoldMessageBox(Caption As String, BoldPrompt As String, Optional FirstLine As String, Optional SecondLine As String, Optional Buttons As VbMsgBoxStyle) As VbMsgBoxResult
  2. Dim s As String
  3. If IsMissing(Buttons) Then Buttons = vbOKOnly
  4. If IsMissing(FirstLine) Then FirstLine = ""
  5. If IsMissing(SecondLine) Then SecondLine = ""
  6.  
  7. s = "Msgbox('" & BoldPrompt & "@" & FirstLine & "@" & SecondLine & "@'," & Buttons & ",'" & Caption & "')"
  8. BoldMessageBox = Eval(s)
  9. End Function
  10.  
usage:

Expand|Select|Wrap|Line Numbers
  1. If BoldMessageBox("Test", "Bold", "nonBold", "", vbAbortRetryIgnore) = vbAbort Then
  2.   BoldMessageBox "Test", "Aborted"
  3. End If
  4.  
Aug 9 '09 #2
ADezii
8,834 Expert 8TB
@Johar
Nice job, Johar. I particularly like that way you encapsulated this functionality within a Function Call, and allowed for Optional Arguments. Thanks for enhancing the usefulness of this Thread - I will actually use this approach more often now, since you have made it easier to implement.
Aug 9 '09 #3
TheSmileyCoder
2,322 Expert Mod 2GB
I can't believe I haven't stumbled across this information earlier. Very nice to know that I don't have to create a custom form to get a bigger degree of variety in my msgbox's.
Sep 12 '12 #4
TheSmileyCoder
2,322 Expert Mod 2GB
Can anyone explain why exactly it is that the simple messagebox gets its functionality expanded by being put into a eval function call?

Are there other functions that you could eval to get more value?
Sep 13 '12 #5
Hoopla3000
7 Nibble
Be careful when using the formatted message box. If the content you want to display contains the '@' symbol, it will mess up the formatting. Maybe you could adjust your function so if the passed parameters contain @, it reverts to the standard message box (without the eval() function).
Dec 5 '12 #6
NeoPa
32,556 Expert Mod 16PB
Re: Code in Post #2.
I'm not sure how this was missed, probably because the effect is nil anyway, but IsMissing() will always return False when passed a string variable. Only Variants can store the Missing flag. For non-Variant variables the syntax to use would be :
Expand|Select|Wrap|Line Numbers
  1. Public Function BoldMessageBox(Caption As String, BoldPrompt As String, _
  2.                                Optional FirstLine As String = "", _
  3.                                Optional SecondLine As String = "", _
  4.                                Optional Buttons As VbMsgBoxStyle = vbOKOnly) As VbMsgBoxResult
  5.     Dim s As String
  6.  
  7.     s = "Msgbox('" & BoldPrompt & "@" & FirstLine & "@" & SecondLine & "@'," & Buttons & ",'" & Caption & "')"
  8.     BoldMessageBox = Eval(s)
  9. End Function
Dec 9 '12 #7
TheSmileyCoder
2,322 Expert Mod 2GB
Technically there is no reason to set the default value of optional string arguments to an empty string, since they are allready an empty string. Unlike a variant variable, string variables (and number variables) cannot be assigned a null value, it will throw an error.

That doesn't mean it can't make sense to write it as NeoPa has done, sometimes it can help to illustrate the intent of the code to write it as NeoPa has.
Dec 11 '12 #8
NeoPa
32,556 Expert Mod 16PB
Absolutely. Spot on.

Particularly in the forums, I find it makes sense to be explicit about such things as it's easier to follow, even if, on the surface, it seems redundant.
Dec 11 '12 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Andrew Baker | last post by:
OK this has me perplexed, puzzled and bamboozled! I have a remoting service which I displayed a message box in. I then wondered what would happen if a client made a call to the service while the...
3
by: Andre Nogueira | last post by:
Hi there. I am developing an application using Visual Basic .Net 2003. So far I have localized my forms and their controls using the VS.net Ide (Setting localized to True, choosing a language and...
3
by: Brian Mitchell | last post by:
Hello, I have a weird problem with my Visual Basic. The text in list boxes, buttons and message boxes are missing when I run the program. Everything looks fine at design time but somewhere when I...
12
by: jburkle | last post by:
Hello all, I am still having an issue where multiple Message Boxes are being displayed to the user from the same form at one time. This issue hides the boxes behind the forms since the forms take...
11
by: Edson Peacock | last post by:
I have a report with sub reports, one of the subreports have 12 text boxes that are 2" high and I want them all to grow if one goes to 3" high. If anyone has any suggestions they are very much...
5
by: HowardChr | last post by:
I have my program set up so that when a button called "Clear" is clicked, it clears all Yes/No fields from a seperate table. The problem is that when that button is clicked, it is coming up with 2...
2
by: =?Utf-8?B?TmF0aGFuIFdpZWdtYW4=?= | last post by:
Hi, I am wondering why the .NET Framework is quite different from Win32 API when it comes to displaying system modal message boxes. Consider the four following types of system modal message...
1
by: Dave | last post by:
Hello all, First I'd like to apologize...This post was meant to be put in my previous post, but I tried many times without success to reply within my previous post. Now here goes... I have a...
1
by: woodey2002 | last post by:
Hi Everyone and many thanks for your time.. I am trying to begin access and a bit of VBA i am enjoying it but I have a annoying problem I just can’t get any where on. My databse mostly includes...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.