insert HtML file in to body of email (inside loop email)

GaryPanic

Smoke me a Kipper,Skipper
Local time
Today, 12:03
Joined
Nov 8, 2005
Messages
3,309
Hey everyone - thanks for your help
- this works a treat
but now I want to enhance it

what i want to do is inset a html file into the body of the email
I have created a publisher file and saved as html ..say

C:\test\pub1.html
:banghead:

how do I get this in to the body ?

code to date below (not the tidiest - but it works)



Private Sub Command0_Click()


Dim MyDb As DAO.Database
Dim rsEmail As DAO.Recordset

Dim OutApp As Object
Dim OutMail As Object
Dim strAttach1 As String

Dim Attachment As String
Dim RefernceNumber As String
Dim attachments As String

Dim FilenameZ As String
Set MyDb = CurrentDb()
Set rsEmail = MyDb.OpenRecordset("bondqry", dbOpenSnapshot)
Dim FilterZ As String
Dim strID As String
Dim i As Integer



For i = 0 To rsEmail.RecordCount


rsEmail.MoveNext
Next i


With rsEmail
.MoveLast
.MoveFirst


Do Until rsEmail.EOF
DoCmd.OpenReport "Bondreport", acViewPreview, , "RefernceNumber=" & rsEmail.Fields(6) & ""
DoCmd.OpenReport "Bondreport", acViewPreview, , "RefernceNumber=" & rsEmail.Fields(6) & ""

DoCmd.OutputTo acOutputReport, , acFormatRTF, "c:\Test\" & .Fields(6) & ".Doc", False
DoCmd.Close acReport, "Bondreport", acSaveYes


strAttach1 = "C:\test\" & rsEmail.Fields(6) & ".doc" & ""


If IsNull(.Fields(11)) = False Then
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

With OutMail


.to = rsEmail.Fields(11)
.Subject = "" & rsEmail.Fields(6)
.HTMLBody = "some blurb.. tied to a table ? " & vbCrLf & _
"Field A: " & vbCrLf & _
"Field B: " & vbCrLf & _
"Field C: "
'.display
.attachments.Add strAttach1


strID = rsEmail.Fields(6)


.send

End With
End If
.MoveNext
Loop

End With




Set MyDb = Nothing
Set rsEmail = Nothing
End Sub
 
You need to parse your HTML text file to read it into a string.
Code:
Open "C:\test\pub1.html"  For Input As #1
Do Until EOF(1)
    Line Input #1, strLine
    strHTML= strHTML & strLine
Loop
Close #1

If you want to add additional text, you'll have to wrap it into the HTML, not just append it.
 
where would I put this ?
 
Preferably somewhere before
Code:
.HTMLBody = "some blurb......
because that code provides your blurb.
 
oops ..

I give that a try - might be a couple of days before I can get back to confirm all ok - long weekend - going to Norway ...

so thanks in advance ..



G
 
Hey - update

It pops a html file in to the first email - fine

but them duplicates itself 2 - and 3 fold itself on the 3 -

so if I send say 50 emails i will get the html in the last email 50 times -
I think I need to clear the html.body rather than just the once ..
hoep this makes sense

G
 
I suppose that could happen that you get the html 50 times if you read the source file every time in the email loop and append it to the previous html text.
 
Any pointers on how to stop this repeating ?
G
 
Are you playing with me?

The pointer was in my last message. You have a loop that is generating 50 emails. It occurs to me that if the html is being added to each of the 50 times that you are reading and adding to the html string each time through the loop. Take the generation of the html string OUTSIDE the loop.
 
Brain fried when asking the question..
will let you known how I get on

G
 

Users who are viewing this thread

Back
Top Bottom