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

Print various external files from within Access

Status
Not open for further replies.

leicklda

Technical User
Mar 18, 2002
46
US
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
 
It's looking like there's not goo way to do what I'd like. Darn.

But 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!
 
I think, using the ShellExecute API would be able to do that.

Declaration, something like this:

[tt]Private Declare Function apiShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" _
(ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) _
As Long[/tt]

One would perhaps usually call it with something like this:

[tt]lngReturn = apiShellExecute(hWndAccessApp, vbNullString, _
rst!Filename, vbNullString, vbNullString, 3)[/tt]

But try instead to call it like this:

[tt]lngReturn = apiShellExecute(hWndAccessApp, "print", _
rst!Filename, vbNullString, vbNullString, 0)[/tt]

i e - use the litteral "print" as second arguement.

Declaration is copy/pasted from Start an app with ShellExecute you could perhaps tweak that routine to fit the purposes, as it contains some errorhandling (i e, what to do if a file isn't associated with any application...).

Roy-Vidar
 
Hi I have tried the code above and it doen't actually send to the printer. It open's it up using Windows and Fax viewer!!!

??

Any idea's?
 
I think it depends a little on the file type, or perhaps the application it's assosiated with. For instance snapshot files will give you the "select printer" thingie, while Word docs, Excel files, text files... will print directly (you may see tha app open, prepare to print, then close). And pdf files will probably also print directly, but still open the application.

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top