[AccessD] SendObject

Andy Lacey andy at minstersystems.co.uk
Sat Aug 6 12:44:28 CDT 2005


Here you go Barbara

Don't forget to set a Reference to the Outlook Object Library and put in
error trapping etc



Function SendOutlookMessage()

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim objOutlookNameSpace As Outlook.NameSpace
Dim objOutlookItem As Outlook.ContactItem
Dim objOutlookFolder As Object
Dim lngCounter As Long
Dim astrRecipients() As String
Dim astrAttachments() As String
Dim strSubject As String
Dim strBody As String

'Put code in here to build up array of recipients and attachments


'Create the Outlook session
Set objOutlook = CreateObject("Outlook.Application")

Set objOutlookNameSpace = objOutlook.GetNamespace("MAPI")
Set objOutlookFolder =
objOutlookNameSpace.GetDefaultFolder(olFolderContacts)

'Create the message
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
  'Add recipients
  For lngCounter = 1 To UBound(astrRecipients)
    Set objOutlookRecip = .Recipients.Add(astrRecipients(lngCounter))
    objOutlookRecip.Type = olTo
  Next
  'Resolve each recipients name
  For Each objOutlookRecip In .Recipients
    objOutlookRecip.Resolve
  Next
  .Subject = strSubject
  .Body = strBody
  .Importance = olImportanceNormal
  For lngCounter = 1 To UBound(astrAttachments)
    Set objOutlookAttach = .Attachments.Add(astrAttachments(lngCounter))
  Next
  .Save
  .Send
End With

End Function

HTH

-- Andy Lacey
http://www.minstersystems.co.uk 



> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com 
> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of 
> Barbara Ryan
> Sent: 06 August 2005 12:03
> To: Access Developers discussion and problem solving
> Subject: Re: [AccessD] SendObject
> 
> 
> Thanks for the info.  Andy, that would be great if you could 
> send an example.....Barb
> 




More information about the AccessD mailing list