VBA Word Wrap?

S

ServiceEnvoy

I've got a command button that creates an outlook email. I then use
fields from the form to fill in places in the subject and body of the
email. I use so much space in the body of the email that the VBA code
tries to wrap and then it turns red and doesn't work. Is there a way
to use more characters/length/word wrap in VBA code or am I just
trying to make the VBA code do too much?

Example code:
..body = "I have a " & [Task/Problem] & " in " & [City] & ", " &
[State] & " " & [Zip] & " and would like to see if you are available
some time in the next few days. Parts will be onsite and the call pays
a flat rate of $30. If you require a higher rate to do the call,
please reply to this email with your offer. We will take the lowest
qualified offer. Please respond ASAP if you're interested and I can
give you more details." & Chr(13) & "WE REQUEST THAT YOU RESPOND IN
SOME WAY TO THIS MESSAGE. After we attempt to contact a technician 3
times and receive no response, we remove that technician." & Chr(13) &
"If you can't do this call, simply reply to this message and let me
know. I'll notate that you responded and keep you in mind for future
work." & Chr(13) & "If you have moved, remember we do calls
nationwide. Just reply to this email with any updates and we'll update
your profile." (I RUN OUT OF SPACE SOMEWHERE HERE BUT STILL NEED
ENOUGH SPACE FOR ANOTHER SENTENCE AND SPACE FOR MY SIGNATURE)
 
G

Guest

I find that long strings are easier for me to follow when need to edit them
later if I assign them to variables, then concatenate them in logical pieces
(even if it were not for the wrap issue). Something like this, perhaps.

Dim MsgRecip as String
MsgRecip = "(e-mail address removed)"

Dim MsgRecip as String
MsgRecip = "This is the subject"

Dim MsgBody as String
MsgBody = "blah, blah, blah"
MsgBody = MsgBody & Chr(13) & " This is line2 blah, blah, blah some more"
MsgBody = MsgBody & Chr(13) & " This is line 3 blah, blah, blah some more"
etc, etc.

Then send something like this:

DoCmd.SendObject acSendNoObject,,,MsgRecip,,,MsgSubject,MsgBody
 
B

BruceM

While I agree that assigning blocks of text to variables makes a lot of
sense, it is often useful to wrap text. In general, use the underscore
character:

Dim strMsg as String
strMsg = "I have a " & [Task/Problem] & " in " & _
[City] & ", " & [State] & " " & [Zip] & _
" and would like to see if you are available " & _
"some time in the next few days. " & _
"Parts will be onsite and the call pays " & _
"a flat rate of $30." & vbCrLf & _
"WE REQUEST THAT YOU RESPOND IN " & _
"SOME WAY TO THIS MESSAGE."

Note that there is a space before the underscore character. Also, in VBA
you can use vbCrLf to go to a new line. I find it more convenient than
Chr(13) & Chr(10). I see that you are using Chr(13) alone, but I believe
you will find this does not always work as intended, although I cannot
provide details.

You may find the most convenient option is to build the string as suggested
in the previous response, using the underscore as needed to make the text
easy to read.
 

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