In order to send an Access 97 report to Outlook 2003 I have taken the following steps:
-Used a PDF creator to allow the user to click on a button and save the report as a PDF in a specified location.
-Created a Module in Access 97 with the code below, which should open outlook, set a message, add the attachment of the
PDF that will have the same file path and name, and allow the user to send it.
-Created a button which should run the module.
The problem is, that I am getting an error that comes up as the following in the code:
'Run-time error '429':
ActiveX component can't create object'
Below is the code:
Sub SendMessage(DisplayMsg As Boolean, 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. (This is where the problem lies...) 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("Nancy Davolio") objOutlookRecip.Type = olTo ' Add the CC recipient(s) to the message. Set objOutlookRecip = .Recipients.Add("Michael Suyama") objOutlookRecip.Type = olCC ' Add the BCC recipient(s) to the message. Set objOutlookRecip = .Recipients.Add("Andrew Fuller") 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. If Not IsMissing(AttachmentPath) Then Set objOutlookAttach = .Attachments.Add(AttachmentPath) End If ' 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
Any help would be appreciated.
(The code comes from this website: http://support.micro....com/kb/161088)