1 Replies - 590 Views - Last Post: 16 July 2013 - 03:35 AM Rate Topic: -----

#1 PianistChris  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-February 13

Sending a MS Access 97 report in MS Outlook 2003 Error

Posted 16 July 2013 - 03:19 AM

Hello,

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)

Is This A Good Question/Topic? 0
  • +

Replies To: Sending a MS Access 97 report in MS Outlook 2003 Error

#2 PianistChris  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-February 13

Re: Sending a MS Access 97 report in MS Outlook 2003 Error

Posted 16 July 2013 - 03:35 AM

Alright, I fixed that error by changing:
Set objOutlook = CreateObject ("Outlook.Application")



to:
Set objOutlook = New ("Outlook.Application")



But I have a problem with the attachment section:
Set objOutlookAttach = .Attachments.Add(AttachmentPath)



It is coming up with the same error as before.

View PostPianistChris, on 16 July 2013 - 03:32 AM, said:

Alright, I fixed that error by changing:
Set objOutlook = CreateObject ("Outlook.Application")



to:
Set objOutlook = New ("Outlook.Application")



But I have a problem with the attachment section:
Set objOutlookAttach = .Attachments.Add(AttachmentPath)



Sorry, this is the error that comes up:
'Run-time error '-1802043389 (94970003)':
Path does not exist. Make sure the path is correct.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1