Quick Question- SendObject

Benjamin Bolduc

Registered User.
Local time
Today, 06:17
Joined
Jan 4, 2002
Messages
169
Hello,

I was wondering if it's possible to send more than one file format to an email with the sendObject method.

I'm tring to include acFormatSNP and acFormatRTF all on the same email as two different attachments. That way if someone can't open the SNP formatted file, the RTF should still work.

Any ideas?

Thanks Alot!
Ben
 
I've never been able to use SendObject to send more than one attachment. You have two choices.

The first choice is to export the report as snapshot and rtf formats to create temporary files. Then create an outlook object that would attach the two files that you just created.

Or, you can use the SendObject method to send the snapshot format, but include a link to Microsoft's site to download the snapshot viewer if they can't view the attachment.

If either of these choices interest you, let me know. I'm more than willing to help.
 
Thanks!

Actually, the way I have it set up now is with that link to the Snapshot Viewer dowload. This is causing problems though, because some people still can't get it to work even after the download. Some people even refuse to download it because they are afraid of virus's.

I don't have much experience in coding other office applications, but if you'd like to help, I'd certainly take you up on the offer :)

Just let me know what I should do.

Thanks alot!
Ben:D
 
Create a new module, name it "modSendAttachments"
insert the following code

Public Sub SendMessage(DisplayMsg As Boolean, strObjectName As String)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim arrAttach(1)
Dim i As Integer
arrAttach(0) = ExportObject(strObjectName, acFormatRTF)
arrAttach(1) = ExportObject(strObjectName, "Snapshot Format")
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")

' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Your Email Recipient")
objOutlookRecip.Type = olTo

' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Your CC")
objOutlookRecip.Type = olCC

' Add the BCC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Your BCC")
objOutlookRecip.Type = olBCC

' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "This is the body of the message." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance

' Add attachments to the message.
For i = 0 To 1
Set objOutlookAttach = .Attachments.Add(arrAttach(i))
Next

' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next

' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Save
.Send
End If
End With
Set objOutlook = Nothing
End Sub



Public Function ExportObject(strObjectName As String, varFormat As Variant)
Dim strPathFile As String
Select Case varFormat
Case acFormatRTF
strPathFile = "C:\Temp\" & strObjectName & ".rtf"
DoCmd.OutputTo acOutputReport, strObjectName, varFormat, strPathFile, False
Case "Snapshot Format"
strPathFile = "C:\Temp\" & strObjectName & ".snp"
DoCmd.OutputTo acOutputReport, strObjectName, varFormat, strPathFile, False
End Select
ExportObject = strPathFile
End Function




You need to change the recipient to, cc, and bcc, subject, and body text info in the SendMessage procedure.

Then to actually send the message, use
Call SendMessage(True, "YourReportName")

If you don't want to view the message before sending, change the first parameter to false.

Let me know how it works for you.

One more thing! While viewing the code, you need to add reference to Microsoft Outlook Object library. Go to tools, references, then check it in the list.
 

Users who are viewing this thread

Back
Top Bottom