Access - Open attachment programmatically

I have an attachment field in my form.  I would like for the user to be able to double click it and open in its default program (ex. - Word doc opens in Word, image opens in default photo viewer, etc.).  This can be accomplished by double clicking > the Manage Attachment dialog appears > select attachment > Open.  I want the series of clicks to be limited to double click > Open.  Any ideas on how to accomplish this?

cogc_itAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
An attachment field can contain multiple attachments, so you might run into troubles using generic code to work with them. However, here's a blog post that might help:

http://blogs.msdn.com/access/archive/2007/08/30/using-vba-code-to-open-a-file-stored-in-the-new-access-2007-attachment-field.aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LambertHeenanCommented:
Have you tried the ShellExecute API method?

See here...
http://www.mvps.org/access/api/api0018.htm
0
cogc_itAuthor Commented:
Thank you for the suggestions, but I was hoping to piggyback on the same logic that Access exhibits to match the file type in the attachment field with the user's default program to open it.  For example, if the attachment is an image, it opens in the user's default image viewer.  

The first suggestions involves first saving the file to a temp directory, which is not desirable.  The second option might work but I don't know enough about the attachment DAO to pass it to the function for opening (and don't really want to know - hope that makes sense).

Thanks for the suggestions.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
The link I posted is the Microsoft Access Team's solution to your exact problem. In other words, the folks who WRITE Access say this is the only way to achieve that. Therefore, it is the only way to do what you ask.
0
cogc_itAuthor Commented:
I didn't see anything in that blog post about "this is the only way" but thanks for your feedback.
0
LambertHeenanCommented:
"The second option might work but I don't know enough about the attachment DAO to pass it to the function for opening (and don't really want to know - hope that makes sense). "

Well no that does not really make much sense at all. If you don't want to know how to use Access then why are you using it? You have been provided two solutions and seem not to want the bother of trying either.

To use the shell execute API all you need to to is copy the code in the link provided and drop it into a standard Access module.

You will then be able to open any file that windows knows about by calling fHandleFile like this...

fHandleFile sttFullPathToTheFileToOpen,1
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
While I share LamberHeenan's objection, I don't see how ShellExecute would work with the Attachment datatype in Access. Attachments are stored in a OLE field in Access, in a structured table arrangement which is accessed via the methods I describe at the links.

I realize the author may not know much about the inner workings of Access, but the method that I provided at the link is the way you get to Attachment fields via VBA code. You cannot do as the author requests, i.e. Doubleclick and then Open. Access Attachment fields don't work that way, since you MUST move through the table hiearchy in order to get to those hidden tables.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.