Run External Programs from Access

P

Peter Hibbs

Hi All

Access 2003.

I have a list box which lists the contents of a folder on the hard
disk, i.e. PDF files, Excel files, Word files, Text files and JPeg
files. I want the user to be able to double click on a filename in the
list which will then run the associated program and display the
relevant document on screen.

I could write some VBA code which would identify the program type from
the extension code, run the program and open the file using the Shell
function but I vaguely remember someone in this forum, within the last
few months, provided a method to do this in a simple way.
Unfortunately I can't find it now, or perhaps I was mistaken. Has
anyone got any ideas or can point me at a suitable Web site.

Thanks.

Peter Hibbs.
 
P

Peter Hibbs

Allen

That was exactly what I was looking for, I knew I'd seen it somewhere.

Thanks again.

Peter.
 
D

Douglas J. Steele

While ShellExecute would work (the code you need's as simple as Call
fHandleFile(FullPathToFile, WIN_NORMAL)), you can also just use
Application.FollowHyperlink FullPathToFile
 
N

najimou

While ShellExecute would work (the code you need's as simple as Call
fHandleFile(FullPathToFile, WIN_NORMAL)), you can also just use
Application.FollowHyperlink FullPathToFile

Sorry for not being not too familiar with coding, do I have to change
the pathtofile to suit my needs, if so, what needs to be inserted
there, as it is giving me variable not defined error when i double
click on the image
thanks
 
D

Douglas J. Steele

Replace FullPathToFile with wherever provides you with the full path to the
file to be opened.

If you've got it stored in a text box on your form, use Me!NameOfTextBox
(where you replace NameOfTextBox with the actual name of your textbox). If
all you've got is the name of the file, but you know the path in question,
you'd use something like "E:\Folder1\Folder2\" & Me!NameOfTextBox

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


najimou said:
Sorry for not being not too familiar with coding, do I have to change
the pathtofile to suit my needs, if so, what needs to be inserted
there, as it is giving me variable not defined error when i double
click on the image
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top