Results 1 to 13 of 13
  1. #1
    Star Lounger
    Join Date
    Feb 2006
    Posts
    71
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Send multiple attachments in one email (Access2003)

    IN VB, want to send two reports (two attachments) in same email. Line below is sending one report correctly. Can second report be adeed to same line?

    DoCmd.SendObject acReport, "Backlog-scrub", "RichTextFormat(*.rtf)", elook, "", "", "Backlog Scrub as Dated -RTF Format", "", True, ""

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Send multiple attachments in one email (Access2003)

    No, SendObject lets you specify only one database object at a time. If you want to send multiple items, you'll have to save them to files on disk first, then use Automation to control Outlook from Access and attach the saved files.
    If you search this forum for attachments.add, you'll find examples, e.g. <post:=583,679>post 583,679</post:>.

  3. #3
    Star Lounger
    Join Date
    Feb 2006
    Posts
    71
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Send multiple attachments in one email (Access2003)

    Viewed suggested post and attempted to use the code listed below. Receive compile message: "User-defined type not defined". when run attempted.
    Currently only attaching one file to test function. Will already have Outlook running. Want email with attachment to be displayed before sending so that additional body text can be added.


    Private Sub Command42_Click()
    Dim objItem As Outlook.MailItem
    Dim objOutlook As Outlook.Application
    Dim blnNeedToQuit As Boolean
    ' Reference Outlook application object
    On Error Resume Next
    Set objOutlook = GetObject("Outlook.Application")
    ' If Outlook isn't running, then create an instance of it
    If Err Then
    Set objOutlook = CreateObject("Outlook.Application")
    blnNeedToQuit = True
    End If
    On Error GoTo AttachmentErr

    Set objItem = objOutlook.CreateItem(olMailItem)
    objItem.To = "cseguin"
    objItem.Subject = " Backlog Scrub"
    objItem.Body = "Select Attachment type to open"
    objItem.Attachments.Add "C:backlog-scrub-report-snp.snp"
    objItem.Display ' or objItem.Send

    AttachmentExit:
    Set objItem = Nothing
    Set objOutlook = Nothing
    Exit Function

    AttachmentErr:
    MsgBox Err.Description, vbExclamation
    If Not objItem Is Nothing Then
    'objItem.Close olDiscard
    End If
    If blnNeedToQuit Then
    'objOutlook.Quit
    End If
    Resume AttachmentExit
    End Sub

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Send multiple attachments in one email (Access2003)

    Have you set a reference in Tools | References... (in the Visual Basic Editor) to the Microsoft Outlook 11.0 Object Library?

  5. #5
    Star Lounger
    Join Date
    Feb 2006
    Posts
    71
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Send multiple attachments in one email (Access2003)

    Yes, Microsoft Outlook 11.0 Object Library is checked. Is there more to it than that?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Send multiple attachments in one email (Access2003)

    That should have been sufficient. Which line causes the "User-defined type not defined" error message?

  7. #7
    Star Lounger
    Join Date
    Feb 2006
    Posts
    71
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Send multiple attachments in one email (Access2003)

    First DIM statement, if I comment it out, it then fails on second

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Send multiple attachments in one email (Access2003)

    That shouldn't happen if the Microsoft Outlook 11.0 Object Library is checked. <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>
    If you select Tools | References..., does any of the checked references begin with MISSING?

  9. #9
    Star Lounger
    Join Date
    Feb 2006
    Posts
    71
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Send multiple attachments in one email (Access2003)

    None are marked MISSING, first 5 are only ones checked.

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Send multiple attachments in one email (Access2003)

    You do have Outlook 2003, don't you? Well, you must have since you have the Outlook library (11.0 is the internal version number for Office 2003).

    I'm afraid I cannot explain the error. If you wish, you can post a stripped down copy of your database. See <post#=401925>post 401925</post#> for instructions. That would enable Loungers to investigate the problem directly.

  11. #11
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Send multiple attachments in one email (Access

    I have exactly the same problem. My main computer refuses to 'talk to' Outllook, and I get the same error.

    But when I move the db to another machine it works fine.

    I have given up trying to solve this.

    I do have Outlook, and it works.
    The other I was surprised to find that if I did a Word Merge to Email, automated from Access, it worked OK and sent the messages with Outlook.
    Regards
    John



  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Send multiple attachments in one email (Access2003)

    What happens if you clear the reference to the Microsoft Outlook 11.0 Object Library and change the code to use late binding:

    Private Sub Command42_Click()
    Dim objItem As Object
    Dim objOutlook As Object
    Dim blnNeedToQuit As Boolean
    ' Reference Outlook application object
    On Error Resume Next
    Set objOutlook = GetObject("Outlook.Application")
    ' If Outlook isn't running, then create an instance of it
    If Err Then
    Set objOutlook = CreateObject("Outlook.Application")
    blnNeedToQuit = True
    End If
    On Error GoTo AttachmentErr

    Set objItem = objOutlook.CreateItem(0)
    objItem.To = "cseguin"
    objItem.Subject = "Backlog Scrub"
    objItem.Body = "Select Attachment type to open"
    objItem.Attachments.Add "C:backlog-scrub-report-snp.snp"
    objItem.Display ' or objItem.Send

    AttachmentExit:
    Set objItem = Nothing
    Set objOutlook = Nothing
    Exit Sub

    AttachmentErr:
    MsgBox Err.Description, vbExclamation
    If Not objItem Is Nothing Then
    objItem.Close 1
    End If
    If blnNeedToQuit Then
    objOutlook.Quit
    End If
    Resume AttachmentExit
    End Sub

    I also changed Exit Function to Exit Sub because you have a sub, not a function.

  13. #13
    Star Lounger
    Join Date
    Feb 2006
    Posts
    71
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Send multiple attachments in one email (Access2003)

    New code worked without clearing reference to Library. Thank you for assistance.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •