Force new line in MsgBox?

  • Thread starter Thread starter el zorro
  • Start date Start date
E

el zorro

Is there a way to force a new line in MsgBox text?

I'm adding information to the Err.Description message. I
want my text to come first, then the canned
Err.Description text to follow, starting on a new line.
The VBA code I'm using in the On Error subroutine looks
like this:

MsgBox "My instructions to the user " & Err.Description

I want the Error Description to start on a new line. Hey,
and if I could italicize it, that would be cool too, but
I don;t want to over-reach here... any ideas? THanks!
 
you can use the VBA constant vbCrLf for a carriage return & line feed which
will start a new line..

MsgBox "My instructions to the user " & vbCrLf & vbCrLf & err.description

will give you two lines......good luck!
 
MsgBox "My instructions to the user " & Err.Description

MsgBox "My instructions to the user " & vbNewLine & Err.Description

Or..

MsgBox "My instructions to the user " & vbCrLf & Err.Description
 
fredg said:
MsgBox "My instructions to the user " & vbNewLine & Err.Description

Or..

MsgBox "My instructions to the user " & vbCrLf & Err.Description

Or ...

MsgBox "My instructions to the user " & vbCr & Err.Description

As far as the MsgBox() function is concerned, the constant vbCr has the
same effect as vbCrLf -- and it's shorter! :-)
 
Room for one more?

If your using A2K onward you could:

MsgBox "My instructions to the user " & Chr(13) & Err.Description


Jamie
 
And another...

The code below allows you to use the @ symbol just like you could in the
good ol' days of Acc97.

Add this to a code module, then just use FormattedMsg where you would
normally use Msgbox. In your prompt type:

[TitleText]@[explanation]@[Steps to resolve]

e.g.

"Cannot Add New Record@A Record with matching key details already
exists@Please modify the key details or press Esc twice to clear the record"

The title comes out in bold. A gap is left between the title and the
explanation and the steps. Your prompt must contain two @ symbols even if
you are not using one of the three sections.

AFAIK this is the only way to get the first line(s) of a message box in bold
since Acc97. I can't remember where I got this from now, but I use it all
the time.



Public Function FormattedMsgBox(Prompt As String, _
Optional Buttons As Long = vbOKOnly, _
Optional Title As String = "Microsoft Access", _
Optional HelpFile As Variant, _
Optional Context As Variant) As Long

'This code produces a formatted error message box.
'The @ character should be used at the end of the title text and the
description text.
'There must be two @ characters even if there is no description text
'The normal message box function in Access 97 supports use of the @
character to create
' formatted message boxes, but subsequant versions do not. Use this method
even if you
' are developing for Access 97 to prevent problems when moving to later
versions of Acess.

Dim strMsg As String

If IsMissing(HelpFile) Or IsMissing(Context) Then
strMsg = "MsgBox(" & Chr(34) & Prompt & Chr(34) & ", " & Buttons & _
", " & Chr(34) & Title & Chr(34) & ")"
Else
strMsg = "MsgBox(" & Chr(34) & Prompt & Chr(34) & ", " & Buttons & _
", " & Chr(34) & Title & Chr(34) & ", " & Chr(34) & _
HelpFile & Chr(34) & ", " & Context & ")"
End If
FormattedMsgBox = Eval(strMsg)
End Function
 
You got that code from:
http://www.trigeminal.com/usenet/usenet015.asp?1033
--
Marsh
MVP [MS Access]





Paul said:
And another...

The code below allows you to use the @ symbol just like you could in the
good ol' days of Acc97.

Add this to a code module, then just use FormattedMsg where you would
normally use Msgbox. In your prompt type:

[TitleText]@[explanation]@[Steps to resolve]

e.g.

"Cannot Add New Record@A Record with matching key details already
exists@Please modify the key details or press Esc twice to clear the record"

The title comes out in bold. A gap is left between the title and the
explanation and the steps. Your prompt must contain two @ symbols even if
you are not using one of the three sections.

AFAIK this is the only way to get the first line(s) of a message box in bold
since Acc97. I can't remember where I got this from now, but I use it all
the time.



Public Function FormattedMsgBox(Prompt As String, _
Optional Buttons As Long = vbOKOnly, _
Optional Title As String = "Microsoft Access", _
Optional HelpFile As Variant, _
Optional Context As Variant) As Long

'This code produces a formatted error message box.
'The @ character should be used at the end of the title text and the
description text.
'There must be two @ characters even if there is no description text
'The normal message box function in Access 97 supports use of the @
character to create
' formatted message boxes, but subsequant versions do not. Use this method
even if you
' are developing for Access 97 to prevent problems when moving to later
versions of Acess.

Dim strMsg As String

If IsMissing(HelpFile) Or IsMissing(Context) Then
strMsg = "MsgBox(" & Chr(34) & Prompt & Chr(34) & ", " & Buttons & _
", " & Chr(34) & Title & Chr(34) & ")"
Else
strMsg = "MsgBox(" & Chr(34) & Prompt & Chr(34) & ", " & Buttons & _
", " & Chr(34) & Title & Chr(34) & ", " & Chr(34) & _
HelpFile & Chr(34) & ", " & Context & ")"
End If
FormattedMsgBox = Eval(strMsg)
End Function


el zorro said:
Is there a way to force a new line in MsgBox text?

I'm adding information to the Err.Description message. I
want my text to come first, then the canned
Err.Description text to follow, starting on a new line.
The VBA code I'm using in the On Error subroutine looks
like this:

MsgBox "My instructions to the user " & Err.Description

I want the Error Description to start on a new line. Hey,
and if I could italicize it, that would be cool too, but
I don;t want to over-reach here... any ideas? THanks!
 
I've visited his site before so it may well have come from there. I didn't
remove the attribution to trigeminal and I'll put one back in so that credit
goes where it is due.
 
Back
Top