Full Version: Ugggh...Underscores within MsgBoxes?
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
nkstrou
Hi all -

I have the feeling this question probably has an easy answer, I just can't find it anywhere. And yes, I have looked - in several places actually!

I want to set up a snippet of code as follows:

CODE
If Msgbox("Line 1 _
Line 2 _
Line 3 _
Line 4 Do you want to do this?", vbQuestion + vbYesNo, "MsgBox Title") = vbYes Then
do X
Else
do Y
End If

I am not pulling any variables into the MsgBox content, so there are no obvious natural breakpoints. The line breaks are for my convenience in reading the code, not because I want to break the line on the screen in that particular place. (so vbCrLf won't help me)

I've tried ending the lines with _ and & _ and neither seems to work. I just get the "Expected list separator or )" message.

I know this is just a dumb formatting thing. What am I missing?

Thanks all!

nkstrou
BananaRepublic
Basically you would add the characters that represents carriage return & line feed.

CODE
MsgBox( _
  "Line 1" & vbNewLine & _
  "Line 2" & vbNewLine & _
  "Line 3" & vbNewLine & _
  "Line 4" & vbNewLine)


HTH.
doctor9
nkstrou,

If you just want breaks in your code, but the text in the message box to continue naturally, just use this structure:

CODE
    If MsgBox("Line 1 " & _
              "Line 2 " & _
              "Line 3 " & _
              "Line 4 Do you want to do this?", vbQuestion + vbYesNo, "MsgBox Title") = vbYes Then
        do X
    Else
        do Y
    End If


With this, your messagebox text would be:

Line 1 Line 2 Line 3 Line 4 Do you want to do this?

Hope this helps,

Dennis
nkstrou
thanks, doctor9 - that was exactly what I needed! thumbup.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.