Print various External documents from Access

D

Darleen

Does anyone know code that will work to print out a series of
non-access files, regardless of what type they are?

I have a table structure where people can "attach" various documents
to their record. Really the table just stores the directory of the
file they've attached. I would like to run a loop through the
filepaths and print out each one.

Everything I've seen on the groups has code specific to a certain
program - IE how to print Word, Excel, PDF, etc.. But is there some
catch-all print syntax to print anything?

I know its possible at least in Windows, because I can go to a
directory, highlight various files, right click, and hit Print. They
all print.

Any help is so greatly appreciated.

Thanks,
Darleen
 
D

Douglas J. Steele

Unfortunately, I don't believe there is an easy solution.

The reason you can do it through Windows Explorer is because the
instructions for each different file extension have been stored in the
registry.
 
D

Darleen

Thanks for the response. That makes sense about the registry values
in Windows being stored for extensions and not in Access. Darn.

I was thinking, what if I were to predict the most common types of
files to be attached and then execute a series of print statements to
print these files.

Example:
dim rst as dao.recordset
Set rst = currentdb.openrecordset("tblAttachedFiles")
do until rst.eof
Select Case rst!Filename
Case "*.doc"
Word doc printing instructions
Case "*.xls"
Excel doc printing instructions
Case "*.pdf"
PDF printing instructions
Case Else
msgbox strFilename & "Must be manually printed"
End Select
rst.movenext
loop

Is this probably the closest I'm going to get? Any other ideas?
Thanks!
 
D

Douglas J. Steele

Actually, it isn't all that hard to decipher what's in the registry, if you
want to spend some time on it.

If you look in the HKEY_CLASSES_ROOT section of the registry, you'll see a
number of entries corresponding to file extensions. If you look at, say, the
..pdf entry, you should see an entry under it for AcroExch.Document. Once you
have that, you look further down in HKEY_CLASSES_ROOT to find the entry for
AcroExch.Document. One of the entries under it should be shell. Expand that,
and you'll see an entry for Print. Expand that, and you'll see an entry for
command. Look at the Default value there, and you should find the command to
print (with %1 indicating that the file name gets substituted there). On my
machine, that key points to

"C:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe" /p /h "%1"

which means that I should be able to print a PDF file using:

Shell("""C:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe"" /p /h """
& strFileName & """")

There's sample code at http://www.mvps.org/access/api/api0015.htm at "The
Access Web" to allow you to read the registry.

Of course, that's a lot of work, and what you have is probably adequate for
most cases.
 
Top