Letter Templates in Access

C

Chip

I have been pounding my head all day and unfortunately have come up
with nothing but a headache. I'm hoping I can get some help on
this... I have several form letters. These letters are sent at
various times via Email to my customers.

Its easy for me to put them as attachments to emails by PDF. But I
want the form letters to be the body of the email, not the
attachments. I'd like the formating to be rich as well.

So I'm trying all manner of combinations of the MailItem object in
VBA, but nothing seems to work correctly. Most of the attibutes work
great, but what I'm having a problem with is the .Body attribute.
What is the correct syntax for a template letter. My code is below.
As you can see, the part .Body is currently set to SharePoint
address. Thats not an absolute requirement, but it would seem to be
more appropriate than other locations. I can put it on a regular
shared server location.

And while I'm at it, in my Word document, how do I code the fields
that should be populate by the database. For example, in a regular
Report, I woudl say Dear &"[Forms]![frmCourses]![fname]"&, but with a
Word document, when I put that in, what comes out, is exactly that,
not the field value..

Private Sub Command574_Click()
On Error GoTo AddTask_Err
' Save record first to be sure required fields are filled.
DoCmd.RunCommand acCmdSaveRecord
Dim outobj As Outlook.Application
Dim outmail As Outlook.MailItem
Set outobj = CreateObject("outlook.application")
Set outmail = outobj.CreateItem(olMailItem)
With outmail
.To = "(e-mail address removed)"
.Subject = "Certification Course Approval"
.Body = "http://emsiweb/Certification Course Form
Letters/EMT EFR Approval.htm"
.Save
.Send
End With
' Release the Outlook object variable.
Set outobj = Nothing
DoCmd.RunCommand acCmdSaveRecord
MsgBox "Approval Sent!"
Exit Sub
AddTask_Err:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description
Exit Sub
End Sub

I'm going to go home and play legos with my kids for a while (really
therapuetic actually) and will visit this later on tonite. Any and
all help is appreciated..

chip
 
M

Mark Andrews

You could look at our email product. It lets you use txt or html saved
reports and embed them into the body of an existing txt or HTML template.
The only difference is we use a third party smtp component instead of
automating outlook.

I don't do Outlook automation much but would guess you need to assign a
string variable to the body.
Can you create the htm file locally and just have images up on the web
somewhere?
Then read the local file into a string variable.
Try a quick test with a hardcoded string variable with the HTML you want
first just to see if that works.

I think you were also asking about word merging, again see the same product.

Note: the html created by Access reports exported to HTML is not always the
greatest.

HTH,
Mark
RPT Software
http://www.rptsoftware.com


Chip said:
I have been pounding my head all day and unfortunately have come up
with nothing but a headache. I'm hoping I can get some help on
this... I have several form letters. These letters are sent at
various times via Email to my customers.

Its easy for me to put them as attachments to emails by PDF. But I
want the form letters to be the body of the email, not the
attachments. I'd like the formating to be rich as well.

So I'm trying all manner of combinations of the MailItem object in
VBA, but nothing seems to work correctly. Most of the attibutes work
great, but what I'm having a problem with is the .Body attribute.
What is the correct syntax for a template letter. My code is below.
As you can see, the part .Body is currently set to SharePoint
address. Thats not an absolute requirement, but it would seem to be
more appropriate than other locations. I can put it on a regular
shared server location.

And while I'm at it, in my Word document, how do I code the fields
that should be populate by the database. For example, in a regular
Report, I woudl say Dear &"[Forms]![frmCourses]![fname]"&, but with a
Word document, when I put that in, what comes out, is exactly that,
not the field value..

Private Sub Command574_Click()
On Error GoTo AddTask_Err
' Save record first to be sure required fields are filled.
DoCmd.RunCommand acCmdSaveRecord
Dim outobj As Outlook.Application
Dim outmail As Outlook.MailItem
Set outobj = CreateObject("outlook.application")
Set outmail = outobj.CreateItem(olMailItem)
With outmail
.To = "(e-mail address removed)"
.Subject = "Certification Course Approval"
.Body = "http://emsiweb/Certification Course Form
Letters/EMT EFR Approval.htm"
.Save
.Send
End With
' Release the Outlook object variable.
Set outobj = Nothing
DoCmd.RunCommand acCmdSaveRecord
MsgBox "Approval Sent!"
Exit Sub
AddTask_Err:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description
Exit Sub
End Sub

I'm going to go home and play legos with my kids for a while (really
therapuetic actually) and will visit this later on tonite. Any and
all help is appreciated..

chip
 

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