Multiple Replace function .HTML

Petros

Registered User.
Local time
Today, 10:48
Joined
Jun 30, 2010
Messages
145
Hi,

i am using the below sending an email

strBody = DLookup("PB_TEMPLATE_BODY", "PB_TEMPLATES", "ID_TEMPLATE=" & Me.ID_TEMPLATE)

.HTMLBody = Replace(strBody, "<<InsertName>>", Me.txtFIRSTNAME)

How do i insert multiple replace conditions? I need to insert at elast 10 more

Thanks!
 
What I do is I have a list of replacement fields in a table and then I run a loop using a recordset:

Code:
Dim rst As DAO.Recordset
 
Set rst = CurrentDb.OpenRecordset("Select MyTag, TextBoxName  From tblTags", , dbOpenForwardOnly)
 
strBody = DLookup("PB_TEMPLATE_BODY", "PB_TEMPLATES", "ID_TEMPLATE=" & Me.ID_TEMPLATE)

 
Do until rst.EOF
  strBody = Replace(strBody, rst(0), rst(1))
Loop
 
.HTMLBody = strBody
 
Thanks boblarson,

below is my part of my code, i am using Exchange and Outlook object libraries. Is there any way around not using DAO?


Dim strEmail, strBody As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Dim strAttachmentPath As String

Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

strBody = Me!TEMPLATE_TEXT

With objEmail
.SentOnBehalfOfName = Me!Emailaddress
.TO = Me!SREMAIL
.CC = Me!SREMAIL
.HTMLBody = Replace(strBody, "[SRFIRSTNAME]", Me.SRFIRSTNAME)

.Send
End With
End Sub
 
Thanks boblarson,

below is my part of my code, i am using Exchange and Outlook object libraries. Is there any way around not using DAO?

Not if you don't want to write a long bit of code to include each item separately and then have to go modify the code if you need to add or remove something. If it is done how I showed, you can have extreme flexibility. DAO is not something to avoid. It is the heart of the Access database.
 
Ok..i have Microsoft Office 12.0 Access Database Engine Object Library installed..i will replace the DAO reference with ACEDAO and test this..

Very kind of you Bob..thanks!
 
Ok..i have Microsoft Office 12.0 Access Database Engine Object Library installed..i will replace the DAO reference with ACEDAO and test this..

Very kind of you Bob..thanks!
The code would stay the same though. And the Microsoft Office Access 12.0 Database Engine Object Library IS DAO when using Office 2007 and 14.0 when using Office 2010.
 

Users who are viewing this thread

Back
Top Bottom