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

printing to a specific printer?

Status
Not open for further replies.

johnnyv

Programmer
Jul 13, 2001
216
CA
I have written an application to print 2 different types of documents, english and french. I need to be able to direct the document to a printer based on it's type ie english goes to one printer french to another.

these printers are accessed via a network, they are not local to the pc that the app will run on

I can not get the program to print to any other printer other than the default printer

I have used the following code to find the engligh printer in question

For Each UsePrinter In Printers
If (UsePrinter.DeviceName = "\\Choprintsvr\oper-hp#1") Then
Set printer = UsePrinter
End If
Next

but when I print the document it goes to the default printer

Can I direct the document to a non default printer or do I have to change the default printer for the pc to be able to print to that printer?


thanks in advance
 

Private Declare Function SetDefPrt Lib "Winspool.drv" Alias "SetDefaultPrinterA" (ByVal PrtName As String) As Long

Private Declare Function GetDefPrt Lib "Winspool.drv" Alias "GetDefaultPrinterA" (RetStr As String, ByRef BufSz As Long) As Long
 


'****WARNING****

Above Post did not mean to submit the GetDefPrt


IT DOES NOT WORK!

SORRY

But the Set default printer does work. All you need to do is pass in the printer name as you would see it in the printer dialog box

Once again my aploigies for the second API which does not work. (I went to change windows and click in the wrong place)
 
Thanks for your reply

I feel abit silly for asking this but could you clearify your code for me. You are declaring a funuctoin called what?

what is the code that is executed inside of the function ?

thnaks again for the responce
 
'I hope this explains what I tried earlier. Put this code
'in a module and once again sorry for putting up my test
'code by mistake.

Option Explicit

Private Declare Function SetDefaultPrinter Lib "Winspool.drv" Alias "SetDefaultPrinterA" (ByVal PrntrName As String) As Long



Public Function SetPrinter(PrinterName As String) As Boolean

On Error Goto SetPrinterError

Dim RetVal as Long

If Trim(PrinterName) = "" Then Exit Function

RetVal = SetDefaultPrinter(PrinterName)

If RetVal = 1 Then
SetPrinter = True
End If

Exit Function
SetPrinterError:

msgbox err.description

End Sub

'There that looks better!

'What you would need to do is know the name of the printer
'you want to change to and pass it to this function. You
'know how to get the names of the printer on the system
'already

 
Working perfectly
thanks for your help !!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top