Page 1 of 3 123 LastLast
Results 1 to 15 of 33
  1. #1
    Pasi is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2013
    Posts
    38

    Need help to email a .txt file as attachment from access

    HI,



    I am trying to run a script to look for the latest file in the path: "C:\Users\me\Desktop\Reports\ and grab the latest file and email it to recipient? Right now my script out put the .txt to a the folder but can figure out how to send that file as attachment?
    Thanks,
    Pasi

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Do you need to look for file properties like modified date or date ctreated? You state that you created a file and you need to email that file. If that is the case use the same path that created the file to add an attachment to your email code.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    Attaching external files to email requires VBA code that opens Outlook as an object and manipulates that object. Fairly common topic in forum. Here is one https://www.accessforums.net/access/...ect-17713.html

    Why do you save textfile? Is this a query that is exported? DoCmd.SendObject will attach a query as a text file and send email.
    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.

  4. #4
    Pasi is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2013
    Posts
    38
    Hello June7,

    Yes this is the exported file to a folder using DoCmd.TransferText acExportDelim, so you saying there is a command to send this as email?

  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,963
    Explore the SendObject method, otherwise the other code in referenced thread.
    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.

  6. #6
    Pasi is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2013
    Posts
    38
    Yes I need file properties to look for latest file withd ate. right now my out put file is stamp with the date like "C:\Users\me\Desktop\Reports\myfile-" & Format(Date, "mm-dd-yyyy") & ".txt"

  7. #7
    Pasi is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2013
    Posts
    38
    What is the right command to use SendObject method can you give me an example?
    Thanks.!

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    The SendObject will not allow you to name the attachment.

    Access/VBA Help has guidelines on SendObject method. Examples are all over the web.
    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.

  9. #9
    Pasi is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2013
    Posts
    38
    Ok Thanks.

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Here is some example code for SendObject. I have not tested the acFormatTXT but I believe this is correct.

    Code:
    Dim strSubject As String
    Dim strBody As String
    Dim strReport As String
    Dim strTo As String
    Dim strCc As String
    Dim strBcc As String
    strSubject = "Insert Subject Line Here"
    strBody = "Insert text to be displayed in the email body"
    strReport = "rptEquip"
    strTo = "you@gmail.com"
    strCc = ""
    strBcc = "me@gmail.com"
    DoCmd.SendObject acSendReport, strReport, acFormatTXT, strTo, strCc, strBcc, strSubject, strBody, True

  11. #11
    Pasi is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2013
    Posts
    38
    Thank you! Do I put this code into my current Access code or create a .vbs file to include this in it?

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    Code is for Access, maybe button Click event. A .vbs file would not be useful.
    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.

  13. #13
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Why are you considering running script? How would this benefit you? I would do ALL of the work from Access and take advantage of the available libraries in Access.

  14. #14
    Pasi is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2013
    Posts
    38
    Thank you so much!

  15. #15
    Pasi is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2013
    Posts
    38
    BTW, this code works file but the output is a text column delimited, Do you know of a way to set the format to "Text delimited? I tried it but I get a popup asking for format?

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 13
    Last Post: 12-05-2013, 06:04 PM
  2. Email with Access report as attachment
    By kmims44 in forum Programming
    Replies: 1
    Last Post: 07-18-2012, 02:38 PM
  3. Sending Report from Access as attachment in Email
    By taimysho0 in forum Programming
    Replies: 16
    Last Post: 02-09-2012, 12:07 PM
  4. Extract file attachment from email to Access
    By bet in forum Import/Export Data
    Replies: 3
    Last Post: 02-02-2011, 07:35 PM
  5. email attachment from Access
    By Gandalf in forum Queries
    Replies: 0
    Last Post: 01-22-2009, 10:03 AM

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