- Joined
- Dec 11, 2007
- Messages
- 1
- Reaction score
- 0
Hi just a quick question,
how do i send a Report generated by MS Access via email to another receipient?
I know that you're meant to use SendObject
But what else do i need? Like how do i define the source of the database, and any other settings, and how do i execute it? Do i have to create a function?
Sorry this is the first time i have touched VBA.
I have writted, with aid, a little code below that sends emails, how does SendObject fit in?
Thanks in advanced!
how do i send a Report generated by MS Access via email to another receipient?
I know that you're meant to use SendObject
Code:
DoCmd.SendObject(ObjectType, ObjectName, OutputFormat, To, Cc, Bcc, Subject, MessageText, EditMessage, TemplateFile)
But what else do i need? Like how do i define the source of the database, and any other settings, and how do i execute it? Do i have to create a function?
Sorry this is the first time i have touched VBA.
I have writted, with aid, a little code below that sends emails, how does SendObject fit in?
Code:
Option Explicit
Sub SendMessage(Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
Dim name1, name2, name3, toStr As String
name1 = "My Name"
name2 = "Another Name"
name3 = "[email protected]"
toStr = name1 & ";" & name2 & ";" & name3
With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(toStr)
objOutlookRecip.Type = olTo
' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "Hopefully this is the last one." & vbCrLf & vbCrLf
.Importance = olImportanceNormal
' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Save
.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
Thanks in advanced!
Last edited: