Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening external files from access - opening with default program 1

Status
Not open for further replies.

Moss100

Technical User
Aug 10, 2004
584
GB
Hello I have a form which has a textbox called txtFilePath

txtFilePath contains the Path, including extension of a file name.

I would like to have a button which opens the file.

I have tried the hyperlink method, and whilst this works OK, it often throws up security warnings.

Could someone recommend some vba which will launch these files without the security warnings - preferable using the default program for the file extension.

Many thanks Mark
 
Take a look at this:

Code:
Option Explicit

Private Sub Command1_Click()
Call OpenDocument([red]"C:\Temp\SomeFile.txt"[/red])
End Sub
[blue]
Public Sub OpenDocument(ByRef strDocPath As String)
Dim G As Long
G = Shell("RUNDLL32.EXE URL.DLL,FileProtocolHandler " & strDocPath, vbNormalFocus)
End Sub[/blue]

You can place this [tt]Public Sub OpenDocument[/tt] somewhere in your code (a standard Module?), pass a valid path + file name with extension, and it is open with the default application.

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 

Andrzejek, you are a genius - thank you for all your help.

Regards Mark
 
Indeed. I thought I'd already done that - how do I tell?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top