Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting a msgbox ??? 4

Status
Not open for further replies.

Aidzo

ISP
Feb 27, 2003
1
GB
Hi all,
I want to add a bit of detail to a msgbox - i.e. different fonts, colours & formats .....any ideas ???
 
Hi,

You cannot format message boxes in that way. The only thing you can do is create a dialog form that looks like a message box with your different fonts etc.

You can add code to dynamically change the .caption property of the labels on the msgbox form to different messages. The only thing that is tricky is sorting out the icons.

In early versions of Access you can format a msgbox with a max. of three lines of text with the top one in bold, by separating each line with @s. In later versions this doesn't work and you need to use this function I found in a few other posts.
Code:
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
    If IsMissing(HelpFile) Or IsMissing(Context) Then
        FormattedMsgBox = Eval("MsgBox(""" & Prompt & _
         """, " & Buttons & ", """ & Title & """)")
    Else
        FormattedMsgBox = Eval("MsgBox(""" & Prompt & _
         """, " & Buttons & ", """ & Title & """, """ & _
         HelpFile & """, " & Context & ")")
    End If
End Function
You can use that to display msgbox using this syntax:
Code:
FormattedMsgBox "Title@1st Msg line@2nd Msg line, vbExclamation,"Custom MsgBox"

Dean.
 
Hi Aidzo,
Dean & Abdulla I'm sure are correct, but just for convenience, I know you can at least capitalize or small case your message by;
MsgBox Format(&quot;Wrong Input&quot;,&quot;>&quot;),,Format(&quot;Yo' Wuz Up?&quot;, &quot;<&quot;)
This puts your message &quot;Wrong Input&quot; in all capital letters, & the title &quot;Yo' Wuz Up?&quot; in small case.
Small example, hope it helps!
 
There is some limited formatting available using MsgBox. From Access help:
Code:
You can use the MsgBox action to create a formatted error message similar to built-in error messages displayed by Access. The MsgBox action permits you to supply a message in three sections for the Message argument. You separate the sections with the &quot;@&quot; character.

The following example displays a formatted message box with a sectioned message. The first section of text in the message is displayed as a bold heading. The second section is displayed as plain text beneath that heading. The third section is displayed as plain text beneath the second section, with a blank line between them.

Enter the following in the Message argument:

Wrong button!@This button doesn't work.@Try another.

Hoc nomen meum verum non est.
 
CosmoCramer

Yes that is correct for access 97, and perhaps previous versions, which I'm not able to check. I have not found this to be available in later versions, I'm afraid.

Roy-Vidar
 
You're right Roy, I haven't tried it since A97...

Another idea might be using CRs and LFs to format it a little:
Code:
&quot;Wrong button!&quot; & vbCrLf & &quot;This button doesn't work.&quot; & vbCrLf & &quot;Try another.&quot;

Hoc nomen meum verum non est.
 
Just tested DeanWilliams's function a little. It seems to give the exact formatting as in 97.

This is going into my library, and he's getting a star;-)

Roy-Vidar
 
I agree - nice post from Dean Williams. Another star from me.
 
Cosmo,
I tried your @ for my Msgbox and it didn't work at all, I'm running 97. In the help, it said for CR use Chr(13) and for LF use Chr(10). These work perfectly!
Just an FYI
 
I just tried this function and am having the following difficulty.

Here is my code:

edit = FormattedMsgBox("Would you like to @EDIT@" & " the company " & tmpnewcomp.Value & "?", vbYesNo, "Edit Company")

I want Edit and the name of the company to be in bold. With this code only the text up until Edit are coming up bold. Am I doing something wrong?

Thanks
 
How are ya aw23 . . . . .

[blue]The first line is always bold up to the first @ delimiter[/blue]. You have no control over it other than extending it with CR & LF. Remember @ starts a new section in the text seperated by a blank line. So it would be something like:
Code:
[blue]edit = FormattedMsgBox("Would you like to EDIT the company [blue][b]@[/b][/blue]" & tmpnewcomp.Value & "?[blue][b]@[/b][/blue]", vbYesNo, "Edit Company")[/blue]

Below is my equivalent of [blue]DeanWilliams[/blue] routine. I've been using it since Access 2k came out. The only difference is I setup global variables so they don't have to be declared for each routine required. Also I don't use the help arguements since I always direct the user what to do.

The [blue]Msgbox[/blue] function in Access 97 had a [blue]neat way of formatting[/blue] the text so it appeared the same as system messages, with 1st line bold and 1 or 2 normal additional lines, each seperated by a blank line. This was achieved by using the [blue]@[/blue] character as an delimiter which resulted in three sections. As an example:

MsgBox "fatal Error 2145[blue]@[/blue]Can't Continue![blue]@[/blue]Notify an Admin" would look like:
Code:
[b]fatal Error 2145[/b]

Can't Continue!

Notify an Admin
The first [blue]@[/blue] skips a line to the next section and ends bold text. The second [blue]@[/blue] just skips a line to the next section. Using [blue]CR & LF[/blue] (or any equivalent Access constant) sections can be added or extended. The following is a good example of what can be done:
Code:
Dim Msg As String, NL As String, DL As String

NL = vbnNewLine
DL - NL & NL

Msg = "A Fatal Error Has Occured" & DL & _
      "It May Be All Over For You!" & _
      "[blue][b]@[/b][/blue]First try the Task Manager . . . ." & NL & _
      "Then Slap The Monitor!" & _
      "[blue][b]@[/b][/blue]Press OK to try Again . . ." & DL & _
      "Press Retry to start over" & DL & _
      "Press Cancel to abort. . . ."
MsgBox Msg would look like:

[b]A Fatal Error Has Occured
It May Be All Over For You![/b]

First try the Task Manager . . . .
Then Slap The Monitor!

Press OK to try Again . . .

Press Retry to start over

Press Cancel to abort. . . .
Using a well know [blue]Eval[/blue] function, this [blue]format is easily carried over[/blue] to successor Access Versions. As such, I designed my own function called [purple]uMsg[/purple] that emulates the MsgBox. In every respect it works exactly the same, even returns the same constants for testing button selections. To further enhance messaging, [blue]Global Variables[/blue] are used so they don't have to be declared in every routine.

I think you get the Idea. Also, [purple]I'm not the first person to take advantage of this since Access 2K hit the street . . .[/purple] Now the code.

In a module in the Modules Window, in the Declarations Section, copy/paste the follwoing code:
Code:
[blue]Public Msg As String, Style As Integer, Title As String
Public Const NL As String = vbNewLine [green]'New Line[/green]
Public Const DL As String = NL & NL   [green]'Double Line[/green]
Public Const DQ As String = """" [green]     'Used by EVal[/green][/blue]
The declarations make the variables [blue]global[/blue]. So you can [purple]use them anywhere with out declaration[/purple], as you'll see.

Now, in the same module, copy/paste the [purple]uMsg[/purple] function below:
Code:
[blue]Public Function uMsg() As Integer
   Beep
   uMsg = Eval("MsgBox(" & DQ & Msg & DQ & "," & Style & "," & DQ & Title & DQ & ")")
End Function[/blue]
Compile & save the code.

You use [purple]uMsg[/purple] in the exact same way as [blue]MsgBox[/blue]. All you have to do is assign Msg, Style, and Title. NL & DL are for custom formatting.

Example using uMsg:
Code:
   Msg = "An Error Has Occured!" & DL & _
         "Resources May Be Low!" & _
         "[blue][b]@[/b][/blue]Close open applications . . ." & _
         "[blue][b]@[/b][/blue]ReBoot if necessary . . ."
   Style = vbCritical + vbOKOnly
   Title = "UnKnown Error! . . ."
   
   Call [purple][b]uMsg[/b][/purple]

Calvin.gif
See Ya! . . . . . .
 
Thanks but it doesn't really help me because I don't need the first line underlined. I really just need some of hte text inside. Is there really no other way?

Thanks
 
Hi,

The only way you can do this is to create a form that looks like a message box.

You can do a print screen of a messagebox to get the image of the icon you want on it.

Don't think there is any other way to format a system messagebox.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top