msg box multi line

murray83

Games Collector
Local time
Today, 11:05
Joined
Mar 31, 2017
Messages
828
i have the following code and have found to make it a new line you need to include
Code:
& vbNewLine &

how ever i have placed this in my code ( as below ) and has the following error

Code:
Private Sub Info_Button_Click()

MsgBox "Time - In the time column you just need to type the time as follows for example 1650, will then be changed by formatting in the cell to show 16:50" & vbNewLine & "Date - To filter by date; this is done by clicking on the button on top of sheet marked Filter Date.  To clear the filter just press on button marked Clear Filter" & vbNewLine & "SKU  - To filter by SKU; this is done by clicking on the button on top of sheet marked Filter SKU.  To clear the filter just press on button marked Clear Filter" & vbNewLine & "Customer - To filter by Customer; this is done by clicking on the button on top of sheet marked Filter Customer.  To clear the filter just press on button marked Clear Filter" & vbNewLine
, vbExit, "Information"

End Sub

thought was maybe missing a comma or such but no luck

thanks in advance
 

Attachments

  • error.jpg
    error.jpg
    92.6 KB · Views: 163
Line continuation character in VBA is " _". A code example is...
Code:
private sub cmd_button_Click()
   dim sql as string

   sql = _
      "SELECT * " & _
      "FROM tTable " & _
      "WHERE This = That;"
  me.recordsource = sql

end sub
vbNewLine is an ascii character, like "A" or "1"

Code:
   debug.print asc(vbNewLine)

hth
 
ok thanks but with a bit more digging have found there was anotehr new function so have done this

Code:
MsgBox "Time - In the time column you just need to type the time as follows for example 1650, will then be changed by formatting in the cell to show 16:50" & vbCr & vbCr & "Date - To filter by date; this is done by clicking on the button on top of sheet marked Filter Date.  To clear the filter just press on button marked Clear Filter" & vbCr & vbCr & "SKU  - To filter by SKU; this is done by clicking on the button on top of sheet marked Filter SKU.  To clear the filter just press on button marked Clear Filter" & vbCr & vbCr & "Customer - To filter by Customer; this is done by clicking on the button on top of sheet marked Filter Customer.  To clear the filter just press on button marked Clear Filter"
, vbExit, "Information"

but now it faults saying

Compile error:

Expected: line number or label or statement or end of statement

but if i comment out the last line of code
Code:
,vbexit, "Information"

it all works fine WTF
 
That's because vbexit is not a valid parameter for Buttons!

If it had been, when you moved off of the line the Access Gnomes would have changed it to vbExit.

Linq ;0)>
 
I also don't see the line continuation character in your code. It's a <space> + <underscore> " _"

To show a new line in text, use vbCrLf, which is two ascii characters, chr(13) + chr(10), a carriage return and a line feed.

I wouldn't write a message box this long, but if I did, I would do...
Code:
    MsgBox _
        "Time - In the time column you just need to type the time as " & _
        "follows for example 1650, will then be changed by formatting " & _
        "in the cell to show 16:50" & vbCrLf & vbCrLf & _
        "Date - To filter by date; this is done by clicking on the button " & _
        "on top of sheet marked Filter Date.  To clear the filter just " & _
        "press on button marked Clear Filter" & vbCrLf & vbCrLf & _
        "SKU  - To filter by SKU; this is done by clicking on the button " & _
        "on top of sheet marked Filter SKU.  To clear the filter just press " & _
        "on button marked Clear Filter" & vbCrLf & vbCrLf & _
        "Customer - To filter by Customer; this is done by clicking on the " & _
        "button on top of sheet marked Filter Customer.  To clear the filter " & _
        "just press on button marked Clear Filter", _
        vbOKOnly, "Information"
hth
 
it does say vbExit

and worked fine before i put in my long winded typing
 

Attachments

  • vbexit.png
    vbexit.png
    1.3 KB · Views: 109
I also don't see the line continuation character in your code. It's a <space> + <underscore> " _"

To show a new line in text, use vbCrLf, which is two ascii characters, chr(13) + chr(10), a carriage return and a line feed.

I wouldn't write a message box this long, but if I did, I would do...
Code:
    MsgBox _
        "Time - In the time column you just need to type the time as " & _
        "follows for example 1650, will then be changed by formatting " & _
        "in the cell to show 16:50" & vbCrLf & vbCrLf & _
        "Date - To filter by date; this is done by clicking on the button " & _
        "on top of sheet marked Filter Date.  To clear the filter just " & _
        "press on button marked Clear Filter" & vbCrLf & vbCrLf & _
        "SKU  - To filter by SKU; this is done by clicking on the button " & _
        "on top of sheet marked Filter SKU.  To clear the filter just press " & _
        "on button marked Clear Filter" & vbCrLf & vbCrLf & _
        "Customer - To filter by Customer; this is done by clicking on the " & _
        "button on top of sheet marked Filter Customer.  To clear the filter " & _
        "just press on button marked Clear Filter", _
        vbOKOnly, "Information"
hth

works like a charm thanks

i thought you put the underscore after the &
 
As far as I can tell, vbExit is not a thing in VBA. Not a constant. Not a member of an Enum.

Linq:
Interestingly, if you do not require variable declaration--so no Option Explicit at the top of the module--'vbExit' will self-declare as a variant with a value of 'empty', and become a valid parameter to pass to the 'Optional Buttons As vbMsgBoxStyle' parameter of the MsgBox function, which then defaults to vbOkOnly. That's why the OP's code worked.

This works in the immediate pane...
Code:
msgbox "test", empty, "test"
Weird but true. :)
 

Users who are viewing this thread

Back
Top Bottom