Results 1 to 15 of 15
  1. #1
    msasteel is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Apr 2014
    Posts
    7

    Send email attachment located in a table from a form.

    I have Access 2007. I have a form where I can attach PDFs, Word documents, etc with an command button. This atachment is then put into a field in a table which has the email address and works fine. The attachments are there in the field with the paper clip in the field title.

    I have a command button with an embedded macro that opens OUTLOOK and the email form with the email address and all the other information inserted perfectly. How do I get the OUTLOOK email to grab the assoiated attachment(s) from the record in the table and send them with the email? I can send the email without the attachment just fine.

    The attachments cannot be located in a common path. They must be in the field in the associated record and each attachement will be different from one record to the next.

    The emails are sent one by one, not as part of a group.

    The form name is TASK DETAILS.
    The email command buttin is called E-mail
    The table is called TASKS
    The attachment command buttin is called Attachments

    What do I need to do this? I have searched many forums , but none have addressed sending an attachment that is is in a field in a record.

    Thanks so much. This has been painful!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Only way I know to do this is to save the item to external location, attach that file to email, send email, then delete the file.
    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.

  3. #3
    msasteel is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Apr 2014
    Posts
    7
    There has to be a better way, but thanks for the response. Seems no one else wants to tackle it either.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    The solution is in post #2. The better way is to not store files in an attachment field if you will need to email said files.

  5. #5
    msasteel is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Apr 2014
    Posts
    7
    You didn't give any direction on how to do that, but how do the files remain with the associated record if they are not a part of the recod? I can't put them into a common location because they change and there are many records with all different required attachments. If I move the file to an alternate location, then I am storing it twice unless I then go back an erase it after it's sent. That might be an alternative, but I don't know how to write that code as part of the embedded macro I already have and I will lose traceability of that attachment to it's associated record. It's not an easy problem, for sure.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I am not sure what you are trying to say in post #5 so

    Using Access to manage files stored on a network is a walk in the park compared to managing files that are stored in Attachment fields.

    Here is a sample DB that will add files to and remove files from Attachments fields. If you want to interact with multiple files in a single field, you will have to add code to iterate the field.

    This sample is the result of helping others and was not designed as an "add and remove" tool. It provides examples of VBA. Refactor to suit your needs.
    Attached Files Attached Files

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Suggestion in post 2 is to copy the file to external location. The file is still in the record. Use the external file for attaching to email then can delete the external file.
    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.

  8. #8
    msasteel is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Apr 2014
    Posts
    7
    It would appear that we are not commuicating at all. I'm not explaining myself well and I don't understand the answers offered. I apologize. When it is suggested that I put the attacments in another location, I assumed that meant on the desktop, or in another folder somewhere on the hard drive or server. Hence my question about how does the attachment stay with the Access record. You folks know among yourselves what you are trying to say, but it may not be clear to those of us who don't do this everyday what you mean. It's no one's fault - it's just experience. It sounds like I need a tutorial with someone looking over my shoulder. I do apperciate the effort by everyone, though.

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    If you were to ask, "Can I email a file in an attachment field?" My answer would be, “I do not believe so."

    If you were to ask "How can I email I file that is in an attachment field?" I would answer, "You must use code to first extract the file from the attachment field."

    I did not make it very clear in post #6 that you can use code to copy the file in the attachment field vs. deleting the file in order to extract it. The unfortunate reality is that nobody posting here knows of a way to email a file in an attachment field without first making a copy of the file and saving it to a temp folder.

    So, the most appropriate question would be, "I have some code that I am trying to use to copy a file from an attachment field and I can not get it to work properly." Then provide an example of what you have tried.

    It is not that we do not want to help. It is only that emailing from an attachment field is not simple. It is complex. It requires the right questions to be asked in order for the proper communications to take place.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I think we do understand what you want and the solution is explicitly described. Not the first thread for this topic. Cannot include a file directly from attachment field as an attachment to an email. The file must reside in a location external from the db. Code can extract a copy of the file from record, save to external location, attach to email, send email, delete the external file.

    Are you saving only one file in the attachment field for each record?
    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.

  11. #11
    Geoff_G is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    2

    Sample Solution

    I think the attached database contains VBA code that solves your problem.

    The Quick Access toolbar has a green, right-pointing arrow, which runs Macro1, which in turn runs the VBA function, SendEmailUsingPlainText(), in Module1.

    I'm away for a day but post back if there is anything you don't understand or if the code doesn't run the way you want and I'll review on my return.
    Attached Files Attached Files

  12. #12
    msasteel is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Apr 2014
    Posts
    7
    Thanks again to all that replied. I will be out of the office for a few days, but will definitely give this a try when I return. Your help is appreciated. I never dreamed this would be such a difficult request. I'll let you know when I return how I made out.

  13. #13
    msasteel is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Apr 2014
    Posts
    7
    I did get to try this, but apparently the DB link was developed on Access 2010 - I have 2007. I get an error that says I need version 14.0.0000.0000 when I try ot look at the macro. I attempted an update, but that didn't work either. I will keep at it and get back to you.

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You are able to open the database? Probably need to change the Outlook library reference in VBA editor.

    The macro isn't even needed. All it does is call the SendEmailUsingPlainText() custom function which can be called by other methods, such as from code behind a button click event.
    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.

  15. #15
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    The example in post #11 uses a macro. The only thing the macro seems to do is call a function named SendEmailWithAttachments

    You can do the same thing in a form. Use the click event of a button and place the following VBA in it.

    call SendEmailWithAttachments()

    IMO deleting the macro would be beneficial. Using VBA to call the function qould allow you to pass arguments to the function SendEmailWithAttachments. Having said that, refactoring the code to fit your app may be a little daunting.

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

Similar Threads

  1. Send email in Outlook with attachment
    By kelkan in forum Programming
    Replies: 1
    Last Post: 02-01-2013, 10:31 PM
  2. Send Email with Attachment VBA Code
    By kevins in forum Programming
    Replies: 2
    Last Post: 10-03-2012, 01:21 PM
  3. Replies: 1
    Last Post: 02-14-2012, 07:08 PM
  4. Replies: 1
    Last Post: 03-09-2011, 08:54 AM
  5. Beginner trying to send email with attachment
    By ahm in forum Programming
    Replies: 2
    Last Post: 03-24-2009, 08:51 PM

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