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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open any file from a form 1

Status
Not open for further replies.

kwor

MIS
Dec 10, 2008
35
AU
I have a form that performs a function.
There are times when users need to select and open other documents relating to the database.
At the moment they must go to explorer, navigate to the directory and double click the appropriate file. The file could be a Word, Excel or other document.
To make life easier, I would like to place a button on the form that will open a file browse dialogue at a specific folder.
The user would select (double click) the required file and file associated application would start, external to Access.
 
A starting point (VBA code):
Application.FollowHyperlink "\path\to\specific folder"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hello Kwor,

If I read what your post properly, you're looking for somthing similar to this. I'm a little new to File IO, and Access itself so let me know if this works or not.

Code:
Private Sub btnOpenFile_Click()

  'Declare a FileDialog object variable.
  Dim myFileDialog As FileDialog
  'Create a FileDialog object as an Open dialog window.
  Set myFileDialog = Application.FileDialog(msoFileDialogOpen)
  'Set the default location for the file dialog  
  myFileDialog.InitialFileName = "C:\"

If myFileDialog.Show <> -1 Then

  'User hit the cancel button, handle accordingly

Else

  'The user selected a file, process accordingly

End If

   'Clean-up
   Set myFileDialog = Nothing

End Sub
 
Oh right, and in regards to being able to open any file you just have to play with the filters propert for the FileDialog I beilve.

So with the above code you would do something like..

Code:
  myFileDialog.filters.add Description, Extensions, Position

Where each of those arguments corresponds to whatever file type you're wanting to open. You can have a look at Microsofts article for more information on manipulating this property:

 
Thanks for the replies everyone.

PHV, exactly what I was looking for. Opening the folder/file dialogue was the easy part - launching the associated application of the selected file had me stumped.

 
I use hyperlinking to open pdf in a msds database. You may need to disable warnings.

Never give up never give in.

There are no short cuts to anything worth doing :)
 
I used the Application.FollowHyperlink method on various file types, including pdf, and have not had a problem with warnings.

Thanks for the comment anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top