Results 1 to 2 of 2
  1. #1
    JulieAHop is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2017
    Location
    Netherlands
    Posts
    15

    Send attachment as email attachment.

    Hi

    I'm storing a technical drawing as an attachment field data type within a table, each item record has a different drawing. What I would like to be able to do is program a button that will attach the attachment to an email, I have done some research and know now that I have to first save the document to a file external to the database, then attach it to an email, but I still have my L plates with visiual basic and am struggling with the code.

    I would be grateful if anyone has got any pointers.

    Thanks

    Julie

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    You can send document INSIDE the database,
    docmd.SendObject acSendReport,"report",acformatPDF,sTo,,,sSubj, sMsg,false

    but if they are not in the db, then you must use a lot of code,below:
    usage:

    Code:
    if Email1( "bob@co.com","subject", "body text", "c:\folder\file.pdf") then
       msgbox "email sent"
    else
       msgbox "email failed"
    endif
    Code:
    Public Function Email1(ByVal pvTo, ByVal pvSubj, ByVal pvBody, Optional ByVal pvFile) As Boolean
    Dim oApp As Outlook.Application
    Dim oMail As Outlook.MailItem
    
    On Error GoTo ErrMail
    
    'NOTE : YOU MUST HAVE THE OUTLOOK REFERENCE CHECKED IN VBE; ctl-G, menu,tools, references
    Set oApp = CreateObject("Outlook.Application")
    Set oMail = oApp.createitem(olmailitem)
    
    With oMail
        .To = pvTo
        .Subject = pvSubj
        If Not IsNull(pvBody) Then .Body = pvBody
        If Not IsMissing(pvFile) Then .Attachments.Add pvFile, olByValue, 1
        
        .Display True
        '.Send
    End With
    
    Email1 = True
    endit:
    Set oMail = Nothing
    Set oApp = Nothing
    Exit Function
    
    ErrMail:
    MsgBox Err.Description, vbCritical, Err
    Resume endit
    End Function

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

Similar Threads

  1. Send email with PDF attachment
    By Rzadziu in forum Reports
    Replies: 8
    Last Post: 10-14-2016, 07:08 AM
  2. Replies: 3
    Last Post: 10-13-2014, 05:48 PM
  3. Send email with Attachment
    By scoe in forum Programming
    Replies: 3
    Last Post: 09-23-2014, 03:02 AM
  4. How to send email without attachment
    By behnam in forum Programming
    Replies: 3
    Last Post: 07-30-2014, 08:24 AM
  5. Send email in Outlook with attachment
    By kelkan in forum Programming
    Replies: 1
    Last Post: 02-01-2013, 10:31 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