Sending Report via Email with VBA

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

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:

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