Results 1 to 3 of 3
  1. #1
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    5,960
    Thanks
    193
    Thanked 730 Times in 666 Posts
    Hello All,

    I've not worked with Outlook from VBA before and I'm having a problem.
    I'm using Office 2003 Pro in Win 7 64Bit.

    Here's my current code:
    Code:
    '******* Begin Send Email
    
           Set miMail = appOL.CreateItem(olMailItem)
           With miMail
               .To = rst![EMail]
               .Subject = "WPOA Annual Dues Statement"
               .Body = zMsgBody & "Bill" & Trim(Str(rst![OwnerID])) & _
                       " Owner: " & rst![OwnerLName]
               .ReadReceiptRequested = True
    '           .Attachment.FileName = "C:\BEKDocs\ARBFiles\EMailBills\Bill" & _
                                       Trim(Str(rst![OwnerID]))
               .Save
           End With   'miMail
    GetOut:
           Set miMail = Nothing
    
    '******* End Send Email
    The code works just fine at creating the emails in Outlook 2003 but I can't get it to attach a PDF file.
    Notice the commented out line above. It seems that both the ATTACHMENTS & ATTACHMENT.FILENAME properties are Read/Only. So is it possible to attach a file via VBA from Access to Outlook? If so, how?
    May the Forces of good computing be with you!

    RG

    VBA Rules!

    My Systems: Desktop Specs
    Laptop Specs


  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Often when you can have "zero or more" of something, you use the Add method of a collection. Try:

    Code:
    Set myAttach = miMail.Attachments.Add(pathToFile)
    (That's "air code", not actually tested.)

  4. #3
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    5,960
    Thanks
    193
    Thanked 730 Times in 666 Posts
    Jefferson,

    Thanks so much!

    Here's my working code:
    Code:
    '******* Begin Send Email
    
           Set miMail = appOL.CreateItem(olMailItem)
           With miMail
               .To = rst![EMail]
               .Subject = "WPOA Annual Dues Statement"
               .Body = zMsgBody & "Bill" & Trim(Str(rst![OwnerID])) & _
                       " Owner: " & rst![OwnerLName]
               .ReadReceiptRequested = True
               zAttFN = zDBPath & "EmailBills\Bill" & _
                        Trim(Str(rst![OwnerID])) & ".pdf"
               Set oMyAtt = miMail.Attachments.Add(zAttFN)
               .Save
           End With   'miMail
    GetOut:
           Set miMail = Nothing
    
    '******* End Send Email
    It's interesting that if I execute the code with Outlook CLOSED the email is placed in the INBOX. But, if the code is executed with Outlook OPEN the email is placed in the Drafts folder...go figure?

    Thanks again.
    May the Forces of good computing be with you!

    RG

    VBA Rules!

    My Systems: Desktop Specs
    Laptop Specs


Posting Permissions

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