sending some files to specific printer from vba code in msaccess

L

Leon

I've got directory full of diferent files word,exel,tif,jpg I need to print
them without dispay I'm looking for away to send them to specified printer.
in vb i'd do somting like that:
Set Printer = Printers(prtidx)

Rem -- Print something
Printer.FontSize = 50
Printer.Print "filename.tif"
Printer.EndDoc

how can I do in
 
L

Leon

Wayne thank you for your replay but I don't need to change printer for
report!!!
I have to print non access files from access!!!
The only way I've found by now is using shell and I don't like it.
Any other ideas?
Somthing like docmd.print "filename","printername"
 
W

Wayne-I-M

Yeah no worries - this is a copy of an answer I gave a while ago to the same
type of question

*****************************

There's a few mehtods - this is just one.


Create a new module


Function PrintDoc()
Dim WordObj As Object
Set WordObj = CreateObject("Word.Application")
WordObj.Documents.Open "Add path to Doc here"
WordObj.PrintOut Background:=False
WordObj.Quit
Set WordObj = Nothing
End Function


'Change Add path to DOC here to the real path to the DOC'


On a form add a button. Put this OnClick


Private Sub ButtonName_Click()
Call PrintDoc
End Sub


'Change ButtonName to what is really is'


OIf course in your case you would add this to the "if" - something like this


if right(field,3) = "doc" then
Call PrintDoc
else
Call PrintExcel
end if


Do the same for the excel file (but change wordobj and createobject)

If you have a number of paths you will need to declare the path as a
variable - link this (DIM) to your table field / form control

*******************************

In the same thread Albert Kallal gave a simply shell call that you may want
to try - another shell but they work fine

http://groups.google.com/group/micr...rint+word+from++group:microsoft.public.access
 
L

Leon

Thanks again.
Your answear is actually what I've made in my application, and I think it's
the worst solution
To have so many functions one for "doc" one for "exel" one for "pdf" other
one for tif...
So much code for simple task as print?
Again as I see it now the only solution is :

Public Declare Function SetDefaultPrinter Lib "winspool.drv" Alias
"SetDefaultPrinterA" (ByVal PrinterName As String) As Boolean
publice sub print myfolder()

oldprintername="printer1"
newprintername="printer2"
SetDefaultPrinter "printer2"
dir()
'do all my prints....
SetDefaultPrinter "printer1"
end sub
Please tell me if there is a more elegant way to do it, couse I hate loading
api's to moduls, I've allready have to many public elements.
 
W

Wayne-I-M

Your answear is actually what I've made in my application, and I think it's
the worst solution

Sorry

If you look at the code you can very simply declare a variable for the doc
typ - take it from the path ie .xls .doc .etc. Defining the printer is just
a case of using either PrinterObject or PrtDevNames can't see what the
problem is with that.

Sorry can't be (don't want to be) any more help

bye
 
L

Leon

Wayne for some reason I feel that I offended you in some way, sorry if I did
it never was my intension
I'm just felt frustrated for need to deal with each kind of object
differently.
Your code is working grate and really thank you for the effort.
Leon
 
W

Wayne-I-M

you don't need to.

I may be wrong about this by the way - but I think that all file types the
microsoft use in office have 3 digits eg .asp .xls .doc .mdb etc etc etc
so all you need to do is to split the path - take the last 3 digits and then
use this as a variable to give you your file type.
you only need one code - not lots.

I woul use a shell call with a declared variable (file type) - but this is a
little over the top

This really is simple you know.
A shell call will open ANY office application (so you don't really need to
get the last digits if you shell it)
you can print the file to any printer (just use PrinterObject or PrtDevNames
- I personaly use PrtDevNames in a private module - but could just as easy be
a public one) - the reason for using private is that I only use this on one
form - where we send out a word doc taken from a frontpage web site - this
means that the doc we are sending is always the same as the printed copy the
client gets)

Best bet would be to use a shell call and define the printer

But if you are not happy with code (LOL - keeps getting simpler) how many
printers do you have - we have 3 in our office - so (here is an idea pinched
from the MS site) why not just copy each report 3 times and have a different
printer set p for each report - you can just add a list or buttons or combo
to your form with the different printers - which ever report you select would
be printed by that AfterUpdate or OnClick from that to the right printer.

Keep it simple - less to go wrong there if you're not too sure about vba

good luck
 
L

Leon

Wayne hello again :)
The complete story is that I've got document management application.
Its manages all type of file's doc,tif,html,pdf,jpeg... up to 4 char
extension.
My clients asked me to select several document and convert them to one PDF
file,
I've decided to use Bullzip pdf printer(that's the story for printer
selection) for this
solution, and the way the bullzip works I have first of all to create single
pdf from each file and then combine them.
I'm righting the classes now and promise to publish complete solution when
I'm done.
Thank you again for your help.
Leon
 

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