Syntax error

A

Ann

I keep getting a syntax error on the following:

MsgBox "The HRA Start Date must be later or _
equal to the Benefit Period Start Date"

I read you need a space and an underscore to go to the next line when typing
code. If I take the space and underscore out and put it all on one line it's
fine. This isn't a long line but some will be and I'd like to know how to do
this. It stops on the word equal. Thanks
 
S

StevenM

To: Ann,

MsgBox "The HRA Start Date must be later or " _
& "equal to the Benefit Period Start Date"

Equals:

MsgBox "The HRA Start Date must be later or equal to the Benefit Period
Start Date"

You need a space after "or" or before "equal"; and a space after the
quotation mark and the underline mark; next line begins with &.

Steven Craig Miller
 
J

Jean-Guy Marcil

Ann said:
I keep getting a syntax error on the following:

MsgBox "The HRA Start Date must be later or _
equal to the Benefit Period Start Date"

I read you need a space and an underscore to go to the next line when typing
code. If I take the space and underscore out and put it all on one line it's
fine. This isn't a long line but some will be and I'd like to know how to do
this. It stops on the word equal. Thanks

Depending on the type of code you used the "next line" character on, you
might need more than just the underscore character.

In this case, you used the underscore in the middle of a string. The
compiler makes no assumptions. A string is delimited by two quote characters.
Your code has only one on the first line. That string is not ended. The
second line could be a variable, not necessarily a string.

Here are a few examples of what you need to do:

In your case:
MsgBox "The HRA Start Date must be later or " _
& "equal to the Benefit Period Start Date"
(Close the string on the first line, use the "join" character (&) at the
beginning of the second line and continue the string by also including quotes
on the second line.)

On three lines:
MsgBox "The HRA Start Date must " _
& "be later or equal to the Benefit " _
& "Period Start Date"

With a variable or a constant:
MsgBox "The HRA Start Date must " _
& vbcrlf & "be later or equal to the Benefit " _
& myVariable & "Period Start Date"

With other parameters of the MsgBox function:
MsgBox "The HRA Start Date must " _
& vbcrlf & "be later or equal to the Benefit " _
& "Period Start Date", vbOKOnly, _
"Message Box Title"

Notice that in that last one I did not include an "&" at the beginning of
the last line because that string is not a continuation from the preceding
line, but is fully contained on that last line.

Hope that helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top