Results 1 to 12 of 12

Thread: Retrieving & Viewing Attachments from Access 2007 or Later ACCDB Files

  1. #1

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Retrieving & Viewing Attachments from Access 2007 or Later ACCDB Files

    I've seen quite a few people asking how to view data from a column of data type Attachment in an Access 2007, 2010 or 2013 database. The answer is that it's not straightforward at all, but it is possible. There are a few suggestions out there but I wanted to provide a purely ADO.NET solution. With a bit of help from some existing posts out there and a bit of messing around, I've come up with the solution attached to this post, which was created in VB 2010.

    If you open the ACCDB file that is included in the project, you can see the schema and data for the Record table. When you run the project you will see ID and Description columns in the upper grid corresponding to the rows in that Record table. When you select a record, the lower grid will be populated with the attachments for that record. Click on the Open button for an attachment and it will open as though you had double-clicked it in Windows Explorer.

    Note that the data for an attachment is saved to a file in the Temp folder when you open it. The app attempts to clean up any such files when it closes but, if the file is not closed before you close the app or you stop debugging in VS instead of closing the form, the temp file will not be deleted.

    If you have any questions, please make absolutely sure that you have read the code and the comments thoroughly before posting it here. If you ask a question that is already answered in the aforementioned code or comments then none at all will be the best response you will get and may not be the worst. Also, this project can be opened in VS 2010 or 2012 and VB 2010 Express or VS Express 2012 for Windows Desktop. I will be creating a C# version but I will not be redoing the project for any older versions of VB. If that's all you have then you can either just read the code file or just install a newer version, which can be done without affecting your current version.

    Note that I am hoping to be able to enhance this sample to allow saving of attachments too but that will take a bit more research and testing. I know what some of the header data on the file contents is but not all at this stage. Also, I'd like to acknowledge the following two posts in helping me to create this sample:

    http://social.msdn.microsoft.com/For...6-ebb44a70fef8
    http://social.msdn.microsoft.com/For...F-8B8A26D54B85
    Attached Files Attached Files
    Last edited by jmcilhinney; Nov 15th, 2012 at 04:18 AM. Reason: Updated attachment

  2. #2

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Retrieving & Viewing Attachments from Access 2007 or Later ACCDB Files

    The attachment in post #1 has been updated with some small changes that do not affect the user experience. The original file contents is now extracted from the file data field when an attachment is opened instead of immediately after the data is retrieved. Also, a clearer indication of the actual purpose of the header contents has been included in the code, although that header data is not really used at this point.

  3. #3

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Retrieving & Viewing Attachments from Access 2007 or Later ACCDB Files

    The attachment in post #1 has been updated again. The temp file created is now deleted when the process that opened it exits. Not all files correspond to a new process though, so those ones will still be deleted when the app itself closes.

  4. #4
    Member
    Join Date
    Oct 2012
    Posts
    61

    Re: Retrieving & Viewing Attachments from Access 2007 or Later ACCDB Files

    Thanks.. Quite Helpful..

  5. #5

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Retrieving & Viewing Attachments from Access 2007 or Later ACCDB Files

    I find it curious that, based on the number of views that this thread has had and the number of views the attachment has had, well under 10% of those who visit this thread download the attached solution. If anyone who falls into the majority group would care to explain why, I would be interested to hear.

  6. #6
    Frenzied Member
    Join Date
    Oct 2012
    Location
    Tampa, FL
    Posts
    1,187

    Re: Retrieving & Viewing Attachments from Access 2007 or Later ACCDB Files

    This is very neat. Thanks for posting it.

  7. #7
    New Member
    Join Date
    Jan 2014
    Posts
    3

    Re: Retrieving & Viewing Attachments from Access 2007 or Later ACCDB Files

    come up with a way to save attachments to the Access DB? I've been beating my head against the wall for a week now trying...

    Peace,
    J

  8. #8

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Retrieving & Viewing Attachments from Access 2007 or Later ACCDB Files

    Quote Originally Posted by Johnsquared2 View Post
    come up with a way to save attachments to the Access DB? I've been beating my head against the wall for a week now trying...

    Peace,
    J
    It appears that it can't be done using ADO.NET, which is rather disappointing. I've seen a few examples using DAO and that appears to be the only option from VB.NET.

  9. #9
    New Member
    Join Date
    Jan 2014
    Posts
    3

    Re: Retrieving & Viewing Attachments from Access 2007 or Later ACCDB Files

    I've tried to use the DAO, but they use the LoadFromFile and SaveToFile methods and those do not show up in my ObjectBrowser as part of DAO 3.6.... has to be a way...

  10. #10
    New Member
    Join Date
    Jan 2014
    Posts
    3

    Re: Retrieving & Viewing Attachments from Access 2007 or Later ACCDB Files

    you have a link to any good examples?

  11. #11
    Frenzied Member
    Join Date
    Oct 2012
    Location
    Tampa, FL
    Posts
    1,187

    Re: Retrieving & Viewing Attachments from Access 2007 or Later ACCDB Files


  12. #12
    Registered User
    Join Date
    Aug 2017
    Posts
    1

    Re: Retrieving & Viewing Attachments from Access 2007 or Later ACCDB Files

    how to insert the file attachment to database using vb 2010

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width