Results 1 to 12 of 12
  1. #1
    New Lounger
    Join Date
    Oct 2014
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Sending PDF files with Outlook 2003 using DoCmd.SendObject

    Hi guys, I hope someone can help. I'm using the Outlook DoCmd.SendObject in VBA and want to attach a PDF file. Outlook only allows DataAccessPage, Form, Modules, Query, Report or Table (or none) - I need to send a PDF attachment. I see there are Add-Ins available but only for 2007 upwards, and I'm using 2003 - any ideas? I'd really appreciate some help.

    Cheers, Sean

  2. #2
    Silver Lounger
    Join Date
    Mar 2014
    Location
    Forever West
    Posts
    2,077
    Thanks
    0
    Thanked 259 Times in 248 Posts
    I've only attached a .pdf file to a message in Outlook, Outlook Express, Windows Mail [only on Vista] and Windows Live Mail, never used a VBA routine for it. The file/s I attach are on my HDD.

  3. #3
    New Lounger
    Join Date
    Oct 2014
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Unfortunately it's MS Access, so VBA it has to be, thanks anyway. Anybody else got some idea? Cheers, Sean

  4. #4
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,191
    Thanks
    48
    Thanked 985 Times in 915 Posts

  5. #5
    New Lounger
    Join Date
    Oct 2014
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi Paul, thanks for trying, but no, they don't help. I'm using the DoCmd.SendObject command in VBA. It does allow for attachments, but on Office ones (DataAccessPage, Form, Modules, Query, Report or Table), but not PDF unfortunately.
    Cheers, Sean

  6. #6
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    You can only send Access objects when using DoCmd.SendObject: http://msdn.microsoft.com/en-us/libr...ffice.15).aspx

    If you want to attach a file that is not related to an Access object, I think you will need to use Office Automation, instantiating an Outlook app from Access and using it to send the message you want. When sending the email message, you can attach whatever file you want, to the message.
    Rui
    -------
    R4

  7. #7
    New Lounger
    Join Date
    Oct 2014
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi Rui, thanks for your input. When trying with Office Automation (the code below), I get an error "Member or Data Member not found" on lines ".ScreenUpdating = True" and ".EnableEvents = True" in the "With Application" call - any further ideas of getting rid of those? Cheers, Sean

    Dim strLocation As String
    Dim OutApp As Object
    Dim OutMail As Object
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    With OutMail
    .To = "sean@dhsystems.co.za"
    .CC = "info@dhsystems.co.za"
    .BCC = ""
    .Subject = "This is the Subject line - Outlook Test 3"
    .Body = "This is the message body - Outlook Test 3"
    .Attachments.Add ("C:\101395.pdf")
    .Display
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing

    With Application
    .ScreenUpdating = True
    .EnableEvents = True
    End With

  8. #8
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    Does Application have anything to do with Office Automation? Where was it declared or instantiated?

    I also don't understand what you are trying to do. You didn't send the email message, using the Display method instead of the Send method, but then you are setting OutMail to Nothing, thus clearing the variable. What exactly are you expecting this code to do?
    Rui
    -------
    R4

  9. #9
    New Lounger
    Join Date
    Oct 2014
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi Rui, thanks for your response. When you mentioned Office Automation in your earlier reply, I tried the above. I'm trying to automate the sending of e-mails with a PDF attachment for a charity organisation, and doing it within Access which is what they're using. Hence I was trying by using the DoCmd.SendObject which is fine, however, I can't send a PDF attachment. The code above is what I've been trying to experiment with. How would you change the code - I really appreciate your input. Many thanks again, Sean

  10. #10
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    To send the email, you need to use the send method, not the display one.

    Quote Originally Posted by sean l View Post
    Hi Rui, thanks for your input. When trying with Office Automation (the code below), I get an error "Member or Data Member not found" on lines ".ScreenUpdating = True" and ".EnableEvents = True" in the "With Application" call - any further ideas of getting rid of those? Cheers, Sean

    Dim strLocation As String
    Dim OutApp As Object
    Dim OutMail As Object
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    With OutMail
    .To = "sean@dhsystems.co.za"
    .CC = "info@dhsystems.co.za"
    .BCC = ""
    .Subject = "This is the Subject line - Outlook Test 3"
    .Body = "This is the message body - Outlook Test 3"
    .Attachments.Add ("C:\101395.pdf")
    .Send
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
    Rui
    -------
    R4

  11. The Following User Says Thank You to ruirib For This Useful Post:

    sean l (2014-10-06)

  12. #11
    New Lounger
    Join Date
    Oct 2014
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi Rui, you're an absolute star. Many thanks - works like a bomb! I've been writing software since 1978 from mainframes in Assembler to PC's, but have never quite cracked the fast moving internet software. Thanks so much - much appreciated. Sean

  13. #12
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    You're welcome, Sean, I am glad I was able to help.

    Regards.
    Rui
    -------
    R4

Posting Permissions

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