Open file with VBA in Access 2010 from text box filepath and text box filename.

I have read that it is possible using VBA to access a file from text boxes.  I have a requirement to access files (source and image) that are placed into a folder that I named "attachments".  I can hyperlink to them, and I attach them to database.  Unfortunately, I have to move the data periodically and all links are broken, and the database grows too fast when attachments are created.  Ideally, I would like to post the filename into a text box and the current repository folder path into a separate text box, and then be able to open the file for access (perhaps using an action button). 

Thanks in advance,

Drew

Answer
Answer

I have read that it is possible using VBA to access a file from text boxes.  I have a requirement to access files (source and image) that are placed into a folder that I named "attachments".  I can hyperlink to them, and I attach them to database.  Unfortunately, I have to move the data periodically and all links are broken, and the database grows too fast when attachments are created.  Ideally, I would like to post the filename into a text box and the current repository folder path into a separate text box, and then be able to open the file for access (perhaps using an action button).  Yes, this is perfectly reasonable.  In code behind your action button, you can do something like this:

       Application.FollowHyperlink Me.txtFilePath & "\" & Me.txtFileName

Or, alternatively, you can call the Windows ShellExecute API, using code such as that posted here on the Access Web:

    http://access.mvps.org/access/api/api0018.htm    
    API: Start an app with ShellExecute

Dirk Goldgar, MS Access MVP 2001-2015
Access tips: www.datagnostics.com/tips.html

1 person was helped by this reply

·

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

 
 

Question Info


Last updated May 6, 2020 Views 2,581 Applies to: