# VBForums CodeBank > CodeBank - Visual Basic .NET >  Retrieving & Viewing Attachments from Access 2007 or Later ACCDB Files

## jmcilhinney

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

----------


## jmcilhinney

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.

----------


## jmcilhinney

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.

----------


## TheThinker

Thanks.. Quite Helpful..

----------


## jmcilhinney

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.

----------


## jayinthe813

This is very neat.  Thanks for posting it.

----------


## Johnsquared2

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

----------


## jmcilhinney

> 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.

----------


## Johnsquared2

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...

----------


## Johnsquared2

you have a link to any good examples?

----------


## jayinthe813

Check this out:

http://msdn.microsoft.com/en-us/libr...ffice.12).aspx

----------


## kvsr_ven1976

how to insert the file attachment to database using vb 2010

----------

