HTML Email

mousemat

Completely Self Taught
Local time
Today, 17:17
Joined
Nov 25, 2002
Messages
233
I have some code that outputs to a text email currently whereby it sets the Venue address in the correct format, for example if there is only one address line, it concatenates the string to exclude the missing line and formats the address correctly

This is part of the code that does that
"" & .Fields(5) + vbCrLf & _
"" & .Fields(6) + vbCrLf & _
"" & .Fields(7) + vbCrLf & _
"" & .Fields(8) + vbCrLf & _
"" & .Fields(9) + vbCrLf & _
"" & .Fields(10)

I have now changed my code slightly as I wish to create a HTML email, the email output works fine, however, if one of the address lines isn't populated, it leaves the blank line in the address on the email.

This is the code I am currently using
sMessageBody = "Dear Delegate<br> " & _
"<br>" & _
"<br>" & _
"This email is confirmation of your place on the following course:<br>" & _
"<br>" & _
"<br>" & _
"" & sSubject & _
"<br>" & _
"" & sCourseDate & _
"<br>" & _
"The course Trainer is: " & sCourseTrainer & _
"<br>" & _
"<br>" & _
"The Course Venue is:" & _
"<br>" & _
"<br>" & _
"" & sVenueName + "<br>" & _
"" & sVenueAddressL1 + "<br>" & _
"" & sVeneuAddressL2 + "<br>" & _
"" & sVenueTown + "<br>" & _
"" & sVenueCounty + "<br>" & _
"" & sVenuePostcode

Is there a way of replicating the same as the vbCrLf and format the address with no blank lines?
 
Last edited:
The first code relied on the entire line becoming null if the field was null.

Your second code uses strings but only a Variant can be null. Presumably only one line can be (or not) there, so use the IIF function (look it up in Help) and check whether the string contains anything: Len(myString)>0 or not.
 
Thanks for that, I will check out the iif function.

several lines of the address might be null
 
Spike

I have changed the strings to variants as i noticed that if one of the fields was blank the code would error.

However, I cant seem to get my head around the iif and len statement. I can see what its supposed to do but there will be times when two fields are null.

Any advice would be helpful
 

Users who are viewing this thread

Back
Top Bottom