Run the Application Associated with a Data File
Problem
You’d
like to find a way to provide a list of existing files, allow users
to select a file, and run the appropriate application for that file.
Windows knows how to do this—for instance, when you
double-click on a file with a .TXT
extension in
Explorer, Windows runs Notepad with that file. How can you provide
this sort of functionality in your own applications?
Solution
Windows provides two API functions,
FindExecutable and
ShellExecute, that make running a related
application possible from within Access. Both functions rely heavily
on the Windows registry, which tracks the relationships between
filename extensions and related executable programs. Figure 11-8 shows the results of running the
REGEDIT.EXE
program, which ships as part of
Windows. REGEDIT allows you to add, edit, modify, or delete file
associations. (The registry editor is named
REGEDT32.EXE
under Windows NT and, though it
looks different, it functions in a similar manner.)
Figure 11-8. REGEDIT.EXE, showing file types registered on a typical system
Get Access Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.