Results 1 to 5 of 5
  1. #1
    Vol71 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    7

    Add attachments from database to email

    I am trying to find the VBA code that adds attachments currently stored in the database to an email. Currently, I have a button that will email the report refernced on my input form. My attachments are stored in a table, but I have built a query for my attachments that wil filter based off the referenced report on the input form. Below is my VBA code to email a report. Thanks

    Private Sub Command587_Click()
    Dim stReport As String
    Dim stWhere As String
    Dim stSubject As String
    Dim NCRNum As String
    NCRNum = Forms![NCR Input Form]![NCR #]
    stSubject = "Supplier Chargebacks NCR " & NCRNum
    stReport = "Supplier Chargebacks"
    stWhere = "[NCR #] = " & "'" & NCRNum & "'"

    Dim rpt
    Dim sRpt As String

    sRpt = "Supplier Chargebacks"
    DoCmd.OpenReport sRpt, acViewDesign
    Set rpt = Reports(sRpt)
    rpt.Caption = "Supplier Chargebacks NCR " & NCRNum
    'rpt.RecordSource = pvQry
    'rpt.OrderByOn = True
    'rpt.OrderBy = sFld
    DoCmd.Close acReport, rpt.Name, acSaveYes
    DoCmd.SendObject acSendReport, stReport, "PDFFormat(*.pdf)", , , , stSubject, , True, ""
    DoCmd.Close acReport, stReport


    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    All you need it the 1 statement:
    DoCmd.SendObject acSendReport, stReport, "PDFFormat(*.pdf)", , , , stSubject, , True, ""

    None of the rest of the code is needed.... It can all be gathered from a form. The report uses its query to read the form and gets all the info.
    Zero coding. But code way works too.

  3. #3
    Vol71 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2015
    Posts
    7
    I am trying to get 2 attachments (1 photo & 1 word document) that are stored in a query to be added to my email. When I click the email supplier chargeback report button, an email with my pdf. report is created for the referenced record, but the 1 photo and 1 word document are not attached to my email. I can go into design view in the query that I built my report off of, click run and see the 2 attachments for the reference report that I am emailing out.

    Is the DoCmd. SendObject statement supposed to add the 2 attachments to my email? If so, it is not working for me.


    Thanks

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    The way I understand it is that you will need to use code to export the attachment. Then you can use VBA to automate Outlook and attach the exported file.

    This DB has some example code to Import and Export attachment type fields. It was created to offer assistance to other members of the forum. It evolved around their needs so the code would need to be refactored to suit your needs.
    Attached Files Attached Files

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    Cannot use SendObject to include files as attachments to an email. Must use email object automation, usually Outlook.

    Files embedded in table must first be exported to be used as attachment, the external file can then be deleted.

    These are common topics.

    Also review https://www.accessforums.net/access/...ect-17713.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Send Multiple csv attachments by email
    By shaunacol in forum Import/Export Data
    Replies: 16
    Last Post: 07-20-2015, 12:22 PM
  2. Using query to group attachments for email
    By Monterey_Manzer in forum Access
    Replies: 7
    Last Post: 05-31-2013, 01:37 PM
  3. If and Multiple Email Attachments
    By beckysright in forum Programming
    Replies: 5
    Last Post: 12-13-2012, 03:25 PM
  4. Send email with attachments not empty
    By JJCHCK in forum Programming
    Replies: 3
    Last Post: 09-23-2011, 10:29 AM
  5. Send email with attachments
    By rbiggs in forum Programming
    Replies: 12
    Last Post: 07-23-2011, 12:50 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums