HTML Template for email merge?

E

Ed

Hi All: Using Access xp and outlook xp.
I would like to email the results of a qry or report to a customer. I
notice when I send a report to email client it gives me a option to select
an html template. I cannot find info on this subject and does it suggest I
can merge data into this html template once created?
My question is can I create an html template that merges the fields of a
record to the body of an email?
thanks, Ed
 
T

Tom Wickerath

Hi Ed,

It looks like our friend "msnews" wasn't too helpful....

If your customer has a Windows-based PC, and they have the Microsoft Snapshot viewer utility
installed (or are willing to install it), then you can use some fairly simple VBA code to send a
report as a snapshot (*.snp) file. This is the only format that is guaranteed to maintain the
exact look and feel of your report. Other report export formats suffer from various problems
(although I haven't tried XML, so maybe that format would be okay).

Here is more information on the Snapshot Viewer (works with Access 2003 as well):
http://www.microsoft.com/accessdev/prodinfo/snapshot.htm

How comfortable are you using VBA code? If you are willing to try using code, you can automate
the process of sending a report as a snapshot, using code similar to this:

DoCmd.SendObject acReport, "rptName", OutputFormat:=acFormatSNP, _
To:=strRecipients, Cc:=strCCRecipients, Bcc:=strBCCRecipients, _
Subject:=strSubject, EditMessage:=True

where strRecipients, strCCRecipients and strBCCRecipients are colon (;) delimited string
variables that contain the e-mail addresses for the "To:", "CC" and "BCC (blind copy) recipeints,
respectively. The variable strSubject is the desired subject of the message. You'll likely want
the EditMessage parameter set to true, otherwise you'll get the Outlook security warning. There
are ways of avoiding the Outlook security warning, but that goes beyond the scope of this reply.
(If interested, google on Outlook Redemption). Note that DoCmd.SendObject works with any MAPI
complient e-mail program, but is limited to a single file attachment.

Here is sample code that you can put in the module associated with the report. Note that this
might look like a lot of code, but most of it is error handling code. Every procedure should
include error handling. As indicated in the first procedure, you can use code to change the
caption of the report. The caption is used as the filename when you create a snapshot file. The
variable shown in this example, strServiceRequested and strBoeingEquipID are picked up from
fields in the report's recordsource of the same name. You could also grab these values from an
open form if you wanted to.


' *************Begin Report Code***************
Option Compare Database
Option Explicit

Private Sub Report_Activate()
On Error GoTo ProcError

' The caption is used for the Snapshot filename (caption.snp)
Me.Caption = strServiceRequested & " Request for " _
& strBoeingEquipID
DoCmd.Maximize

ExitProc:
Exit Sub
ProcError:
MsgBox "Error: " & Err.Number & ". " & Err.Description, , _
"Error in Report_Activate event procedure..."
Resume ExitProc
End Sub

Private Sub Report_Close()
On Error GoTo ProcError

DoCmd.Restore
ExitProc:
Exit Sub
ProcError:
MsgBox "Error: " & Err.Number & ". " & Err.Description, , _
"Error in Report_Close event procedure..."
Resume ExitProc
End Sub

Private Sub Report_NoData(Cancel As Integer)
On Error GoTo ProcError

MsgBox "There is no data available for this report.", _
vbInformation, "Metrology Database"
Cancel = True

ExitProc:
Exit Sub
ProcError:
MsgBox "Error: " & Err.Number & ". " & Err.Description, , _
"Error in NoData event procedure..."
Resume ExitProc
End Sub

' *************End Report Code***************

You can also export the results of a query to a text file or an Excel file, and then use VBA code
to attach the file to a new e-mail message. Use DoCmd.TransferText to export a query to a text
file. Here are examples of using these methods, where strSourceName is the name of the query and
strFileName is the complete name (path + filename + .xls extension) of the Excel document:

DoCmd.TransferText acExportDelim, SpecificationName, _
strSourceName, strFileName, HasFieldNames:=True

Use DoCmd.TransferSpreadsheet or DoCmd.OutputTo to export a query to an Excel file. One
difference in these two methods is that DoCmd.TransferSpreadsheet will not replace an existing
spreadsheet of the same name, whereas DoCmd.OutputTo will. There may be other limitations as
well.

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, _
strSourceName, strFileName, True

DoCmd.OutputTo acOutputQuery, strSourceName, acFormatXLS, _
strFileName, AutoStart:=0

You would then use a procedure to create a new message in Outlook and attach one or more files to
the message. Post back if you wish to pursue this avenue.

The easiest method, in my opinion, is to send a report as a snapshot file. Of course, this
requires a customer who is willing to install the snapshot viewer utility.

Tom
______________________________


I don't know
______________________________

"Ed" <ed@nospamplease_or_not.com>

Hi All: Using Access xp and outlook xp.

I would like to email the results of a qry or report to a customer. I
notice when I send a report to email client it gives me a option to select
an html template. I cannot find info on this subject and does it suggest I
can merge data into this html template once created?
My question is can I create an html template that merges the fields of a
record to the body of an email?
thanks, Ed
 

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