Open an Attachment

KDWW
KDWW used Ask the Experts™
on
I am developing a form in Access 2007with a control that calls  a pdf attachment in a table.  How can I,  programmatically, 'Open' the attachment that requires NO user intervention?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jeffrey CoachmanMIS Liason
Most Valuable Expert 2012

Commented:
I will presume that "Somewhere" you have the Path and file name stored...

You can use this:
Application.FollowHyperlink "c:\YourFolder\YourPDF.pdf"
...if you have the path an name stored in a field (variable, Control, ...etc)
Then try this:
Application.FollowHyperlink YourObjectThatContainsThePDFPathAndName

Jeffrey CoachmanMIS Liason
Most Valuable Expert 2012

Commented:
Or this if you need more control over the app.

Dim varApp As Variant
varApp = Shell("C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe c:\YourFolder\YourPDF.pdf", vbNormalFocus)

(here you would have to use your path to your Adobe PDF viewer executable)
How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

Author

Commented:
It appears Danishani has a solution that I could work with.  The blog is interesting and right now I'm trying to see how to work it in to what I already have.  The PDF document(s) already in a table field as attachments. I am using a macro to open a form with the appropriate record and attachment field in the control.  Now I just need to 'pull out' the pertinant parts of your sample to make it work -- to be honest I don't know if I can make that leap by myself. I couldn't fine anything in the macro that, I thougt, I would be able to use.  Do  you have a hint that I could latch onto to close the loop?
 
Jeffrey CoachmanMIS Liason
Most Valuable Expert 2012

Commented:
Just be aware that  although the Attachment datatype uses less space, most developers still prefer to link to files instead.
Then only the small snippets of code I posted will be all you need to open the file.

The attachment datatype is great if you will have a few small attachments for each record.

Also if the files (pdfs) are stored in the Database as attachments (BLOB data), if the DB gets corrupted, you may loose the attachments as well.

There is no right or wrong here, I am just giving you the pros and cons of both methods.

;-)

JeffCoachman
You place the Functions into a Module in your Database.

Change the second Function accordingly the TableName and the FieldName.

Then in your Command Button in your Form:
TestOpenFirstAttachmentAsTempFile


HTH,
Daniel

Author

Commented:
I must be doing something wrong.  I believe I followed your instructions but after clicking on the command button, I get a return message that the 'database name' can't find the object 'TestOpenFirstAttachmentAsTempFile()'.
I have tested this and it worked fine.

Do you placed the code into a Module?

Author

Commented:
Yes.  

Author

Commented:
And you did mean that 'TestOpenFirstAttachmentAsTempFile()' be put into the Click event of the command button, correct?
Yes, try without the closing brackets. Only TestOpenFirstAttachmentAsTempFile.

Author

Commented:
Tried it, same results.
Hi again,

I have made a Test Database, so you can see how it suppose to work.
Hope you can then apply it in your Database as well.

An example is sometimes more helpful.

HTH,
Daniel testAttach.accdb

Author

Commented:
Danishani, it worked!!  Thank you, thank you.  Sorry you had to resort to 'show and tell' but it pointed out a couple of obvious oversights I was experiencing.  It worked to the point that I can work it into my original concept and move on.  Phew!!!!
Glad to hear you got it working!

Good luck further with your project.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial