UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Attach File To Already Saved Draft, Access 2016    
 
   
aggiemarine07
post Sep 10 2019, 12:34 PM
Post#1



Posts: 48
Joined: 7-January 11



I recently discovered about the ability to use VBA to attach files to already created drafts using the EntryID but I am unsure as to how to proceed and write the VBA. This is what I would like to accomplish:

1) Take a template email that I have saved (how do i find the EntryID?)
2) Create a new email from this template
3) Attach the export of a file to this email

Is this possible? Thanks in advance!
This post has been edited by aggiemarine07: Sep 10 2019, 12:35 PM
Go to the top of the page
 
DanielPineault
post Sep 10 2019, 01:16 PM
Post#2


UtterAccess VIP
Posts: 6,843
Joined: 30-June 11



You need to get the EntryId at the time of creating the Draft and save it for later use. Otherwise, you will need to bind to the Draft using another criteria (subject, something in the body, ...).

--------------------
Daniel Pineault (2010-2019 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
ADezii
post Sep 10 2019, 02:05 PM
Post#3



Posts: 2,630
Joined: 4-February 07
From: USA, Florida, Delray Beach


QUOTE
1) Take a template email that I have saved (how do i find the EntryID?)
2) Create a new email from this template
3) Attach the export of a file to this email

  1. Create an Outlook Template (*.oft) as you previously have done. By Default it will be saved in the Folder C:\Users\<UserName here>\AppData\Roaming\Microsoft\Templates\.
  2. I created a Template in this Default location and named it Demo.oft.
  3. Using Early Binding I
    1. Created an Instance of Outlook.
    2. Created an E-Mail Item from the Demo.oft Template in the Inbox Folder using the CreateItemFromTemplate() Method
    3. Listed some basic information.
    4. Attached a File named Test.xlsx in the C:\Test\ Folder.
    5. Displayed the E-Mail in the Outlook Window (did not Send it).
  4. Code Definition:
    CODE
    Dim oLook As Outlook.Application
    Dim oMail As Outlook.MailItem
    Dim olns As Outlook.Namespace
    Const conPATH_TO_TEMPLATES = "C:\Users\<UserName here>\AppData\Roaming\Microsoft\Templates\Demo.oft"

    Set oLook = New Outlook.Application
    Set olns = oLook.GetNamespace("MAPI")
    Set oMail = oLook.CreateItemFromTemplate(conPATH_TO_TEMPLATES, oLook.Session.GetDefaultFolder(olFolderInbox))


    With oMail
      .To = "PeterPan@GMail.com"
      .Body = "Text in Body of E-Mail"
      .CC = "SomeBody@aol.com"
      .BCC = "SomeBodyElse@Comcast.net"
      .Subject = "New Employee Benefits Package"
      .Attachments.Add "C:\Test\Test.xlsx"
        .Display        'Displays E-Mail without sending
      
        '.Send          'Automatically Sends E-Mail
    End With
  5. Modify the Code to meet your specific needs.
  6. Should you have any questions, feel free to ask.

This post has been edited by ADezii: Sep 10 2019, 02:06 PM
Go to the top of the page
 
aggiemarine07
post Sep 11 2019, 07:44 AM
Post#4



Posts: 48
Joined: 7-January 11



@Adezii thank you! code worked but i modified it slightly to include dynamic paths and my file which has a dynamic ending (i.e. today's date). Really appreciate the help!

CODE
Private Sub Command14_Click()

Dim oLook As Outlook.Application
Dim oMail As Outlook.MailItem
Dim olns As Outlook.Namespace

Dim oTemplatePath As String
    oTemplatePath = CurrentProject.PATH & "\email templates\PLOG Release Template.oft"

'Const conPATH_TO_TEMPLATES = "C:\Users\gregory.williams2\Desktop\Project BCM\email templates\PLOG Release Template.oft"

Dim oMailPath As String
Dim oMailFileName As String

Set oLook = New Outlook.Application
Set olns = oLook.GetNamespace("MAPI")
Set oMail = oLook.CreateItemFromTemplate(oTemplatePath, oLook.Session.GetDefaultFolder(olFolderInbox))

With oMail
'  .To = "john@example.com"
'  .Body = "Text in Body of E-Mail"
'  .CC = "SomeBody@aol.com"
'
'  .Subject = "New Employee Benefits Package"
        oMailPath = CurrentProject.PATH & "\"
        oMailFileName = Dir(oMailPath & "*.zip")
  .Attachments.Add (oMailPath & oMailFileName)
    .Display        'Displays E-Mail without sending
    
End With

End Sub
Go to the top of the page
 
ADezii
post Sep 11 2019, 07:58 AM
Post#5



Posts: 2,630
Joined: 4-February 07
From: USA, Florida, Delray Beach


yw.gif , happy to hear that you got it to work.
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    19th September 2019 - 03:31 AM