Problem with repeated Replace function editing HTMLBody

T

Tony Vrolyk

I am using Outlook automation to create an HTML email and insert data from
my application. The automation uses a template in which there are several
bits of text like [EMPLOYEE], [FROM], etc. I am tyring to use the replace
function to replace each of these with data but only the first on in a
series works. The second and subsequent ones appear to simply get skipped or
fail without errors. the data being used to replace is some from a DAO
recordset and some from the current form. Here is a snippet of what I am
doing

'open recordset, CreateItemFromTemplate, set variables, etc
strSubject = Replace(.Subject, "[EMPLOYEE]", Me.cboEmployee.Column(1))
strBody = .HTMLBody
strBody = Replace(strBody, "[CONTACT]", rst!ContactName)
strBody = Replace(strBody, "[EMPLOYEE]", strOutEmployee)
strBody = Replace(strBody, "[FROM]", strFrom)
strBody = Replace(strBody, "[TO]", strTo)
strBody = Replace(strBody, "[RETURN]", strReturn)
'several lines to build up the strTeamMember variable
strBody = Replace(strBody, "[ADMINTEAM]", strTeamMember)
.HTMLBody = strBody
'etc...

In the subject the [EMPLOYEE] gets replaced OK. In the body [CONTACT] and
[ADMINTEAM] get replaced OK but the others are just left alone. Maybe the
problem should be obvious and I am just having a dumb a** attack. So if
anyone can help it would be appreciated.

Tony
 
J

John Nurick

According to Help, Replace defaults to a case-sensitive comparison
(vbBinaryCompare), so replacing [FROM] and won't find [From]. Try

Replace(strBody, "[FROM]", strFrom, , , vbTextCompare)

Also, check that the tokens in the templat match those in your code
(e.g. is it [FROM] or [FROM:]

I am using Outlook automation to create an HTML email and insert data from
my application. The automation uses a template in which there are several
bits of text like [EMPLOYEE], [FROM], etc. I am tyring to use the replace
function to replace each of these with data but only the first on in a
series works. The second and subsequent ones appear to simply get skipped or
fail without errors. the data being used to replace is some from a DAO
recordset and some from the current form. Here is a snippet of what I am
doing

'open recordset, CreateItemFromTemplate, set variables, etc
strSubject = Replace(.Subject, "[EMPLOYEE]", Me.cboEmployee.Column(1))
strBody = .HTMLBody
strBody = Replace(strBody, "[CONTACT]", rst!ContactName)
strBody = Replace(strBody, "[EMPLOYEE]", strOutEmployee)
strBody = Replace(strBody, "[FROM]", strFrom)
strBody = Replace(strBody, "[TO]", strTo)
strBody = Replace(strBody, "[RETURN]", strReturn)
'several lines to build up the strTeamMember variable
strBody = Replace(strBody, "[ADMINTEAM]", strTeamMember)
.HTMLBody = strBody
'etc...

In the subject the [EMPLOYEE] gets replaced OK. In the body [CONTACT] and
[ADMINTEAM] get replaced OK but the others are just left alone. Maybe the
problem should be obvious and I am just having a dumb a** attack. So if
anyone can help it would be appreciated.

Tony
 
T

Tony Vrolyk

STUPID OUTLOOK HTML!!!!!

I put in a few debug.prints to see how the string was being modified. Well
since the template is in HTML Outlook decided to put in a bunch of SPAN
crap. I am no web developer and I have no idea what that is but for some
reason they were showing up in the middle of the bracketted text I was
trying to replace. If course I didn't see that when viewing the template
because it was part of the HTML code.

Well I copied out the text to Notepad, deleted it from the template and then
copied it back in. Then I viewed the source of the message and could see
that the spanning crap was gone.

It is working fine now. How frustrating!!!!!!

Thanks for your help anyway, at least I learned something.

Tony
 

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