Continue code onto next line

G

Guest

I have a command button in a form that initiates email and I have coded the
email addresses I want it to use, problem is there are so many that the text
is too long and wraps onto the next line except now I get a syntax error and
I have forgotten what sign to use when you want to continue with the same
line onto the next.

Help.

Thanks! Stacey
 
S

SusanV

Under score (_)

If you are wrapping something in quotes. like a SQL statement, close quotes,
_ & then on next line open quotes like so:

"This is the " _ &
"right way"
 
G

Guest

Now I am getting invalid character and it highlights the under score?
Any other ideas? I know that's right.
 
G

Guest

I condensed it down because all it is are email addresses:

Const SCAREmailList = "(e-mail address removed);[email protected]"
"(e-mail address removed);[email protected]"

DoCmd.SendObject acSendNoObject, , , SCAREmailList, ,

Could it be just too long of a line for the Const?

Thanks again
 
S

SusanV

You have your variable as multiple addresses individually enclosed in
quotes, which is not going to populate the variable correctly. The proper
format for multiple addresses is to separate with a semicolon, all within
one set quotes (although if you are using Outlook it can handle commas just
as well if it's set that way in options).

So your variable would be something like:

maillist = (e-mail address removed);[email protected];[email protected]

To break yours up into readable chunks, something like:

Const SCAREmailList = "(e-mail address removed);" _ &
"(e-mail address removed);" _ &
"(e-mail address removed);" _ &
"(e-mail address removed)"

Is this indeed a static list? If not you can loop through a recordset to get
an updated mailing list rather than hard-coding it. This page has a good
example:

http://www.tek-tips.com/viewthread.cfm?qid=55282
 
M

Marshall Barton

SusanV said:
To break yours up into readable chunks, something like:

Const SCAREmailList = "(e-mail address removed);" _ &
"(e-mail address removed);" _ &
"(e-mail address removed);" _ &
"(e-mail address removed)"



Careful there, that should be:

Const SCAREmailList = "(e-mail address removed);" & _
"(e-mail address removed);" & _
"(e-mail address removed);" & _
"(e-mail address removed)"
 
S

SusanV

Hey Marshall,

Thanks for the response. Does it matter? I've done this kind of linebreak /
concat all of the following ways at various stages of learning and all seem
to work:

Const SCAREmailList = "(e-mail address removed);" & _
"(e-mail address removed);"

Const SCAREmailList = "(e-mail address removed);" _ &
"(e-mail address removed);"

Const SCAREmailList = "(e-mail address removed);" _
& "(e-mail address removed);"


Not being cocky, just wondering if it's "bad practice" or if other versions
might be more persnickety? (I use Access 2000 or 2003)...

Thanks for the insight,

Susan
 
D

Douglas J Steele

1 and 3 are okay, but I'm very surprised that 2 works. All I've got
available at the moment is Access 97, and it definitely won't accept option
2: it pops up "Compile error: Invalid character", and highlights the
underscore character.

I don't believe either 1 or 3 is better than the other: it's a matter of
personal taste.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


SusanV said:
Hey Marshall,

Thanks for the response. Does it matter? I've done this kind of linebreak /
concat all of the following ways at various stages of learning and all seem
to work:

Const SCAREmailList = "(e-mail address removed);" & _
"(e-mail address removed);"

Const SCAREmailList = "(e-mail address removed);" _ &
"(e-mail address removed);"

Const SCAREmailList = "(e-mail address removed);" _
& "(e-mail address removed);"


Not being cocky, just wondering if it's "bad practice" or if other versions
might be more persnickety? (I use Access 2000 or 2003)...

Thanks for the insight,

Susan
 
S

SusanV

Thanks Doug!

These days I generally use:
"... line " & _
"continued line..."

I'm trying to get my code to some sort of standard - I'm finding as I go
into older forms (and even older databases) that I can't make heads or tails
of some of the code and wind up rewriting it rather than reverse-engineer
it. Huge waste of time!!

Any particularly good references (web sites especially) on best practices
for this sort of thing?

Thanks again,

Susan



Douglas J Steele said:
1 and 3 are okay, but I'm very surprised that 2 works. All I've got
available at the moment is Access 97, and it definitely won't accept
option
2: it pops up "Compile error: Invalid character", and highlights the
underscore character.

I don't believe either 1 or 3 is better than the other: it's a matter of
personal taste.
 
G

Guest

I just saw this is another sample of code for something else I was searching
on and tried it - & _ and this is what worked.

Thanks for everyones thoughts and great help as usual!!!!

One other question if possible, in the Body Text of the email is there a way
instead of having the text all run together i.e.:
File Name, Part Number and Part Name
to have it return after each field and have its own line in the Body Text
i.e.:
File Name
Part Number
Part Name

THANKS!
 
S

SusanV

To insert linebreaks use & vbCrLf & ...dim a string for the body text and
set it something like this:

Dim body as String
Dim file as String
Dim partno as String
Dim part as String

file = [FileName]
partno = [Part Number]
part = [Part Name]

body = "See attached file " & file & " regarding your order." _
& vbCrLf & "Part Number: " & partno _
& vbCrLf & "Part Name: " & part



Assuming the filename is YourOrder.txt and the Part Number is 123, Part Name
is Widget, this would output as:

See attached file YourOrder.txt regarding your order.
Part Number: 123
Part Name: Widget


Will that help you? You can play with this using the immediate window by
adding the line debug.print body directly below the body = line, see what
you have before actually sending emails.

Susan
 
G

Guest

That worked perfect! Thanks!

SusanV said:
To insert linebreaks use & vbCrLf & ...dim a string for the body text and
set it something like this:

Dim body as String
Dim file as String
Dim partno as String
Dim part as String

file = [FileName]
partno = [Part Number]
part = [Part Name]

body = "See attached file " & file & " regarding your order." _
& vbCrLf & "Part Number: " & partno _
& vbCrLf & "Part Name: " & part



Assuming the filename is YourOrder.txt and the Part Number is 123, Part Name
is Widget, this would output as:

See attached file YourOrder.txt regarding your order.
Part Number: 123
Part Name: Widget


Will that help you? You can play with this using the immediate window by
adding the line debug.print body directly below the body = line, see what
you have before actually sending emails.

Susan




SMac said:
I just saw this is another sample of code for something else I was
searching
on and tried it - & _ and this is what worked.

Thanks for everyones thoughts and great help as usual!!!!

One other question if possible, in the Body Text of the email is there a
way
instead of having the text all run together i.e.:
File Name, Part Number and Part Name
to have it return after each field and have its own line in the Body Text
i.e.:
File Name
Part Number
Part Name

THANKS!
 
P

PC Datasheet

Susan,

Consider using the following for your standard. It's more readable:
"... line " _
& "continued line..."

An example where yours does not work is a message box.
This will NOT work:
MsgBox "Message String",, & _
"Title String"

This will work:
MsgBox "Message String",, _
"Title String"

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com

If you don't get the help you need in the newsgroup, I can help you for a
very reasonable fee. Over 1000 Access users have come to me for help.
 
S

SusanV

Well, the second would not work as you would be concatenating the message
string and title string into a single string which the syntax would see as
simply being the message string...
 

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

Similar Threads

Code Question 7
Error message 2
Horizontal Line 9
text wrapping in coding lines 2
Continue Code to next line 3
cannot filter continuous form data 2
moving to next line oddity 3
form / report font discreptancy 0

Top