Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Change Default Printer


Hello!i amn trying to add a Visuail basic 6 code to an excisting code that has thepurpose to change the current default printer to another printer by name andthen after the printer to change back to the old default printer again...Anyone knows how to do this easy??




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
How Can I Change The Default Printer At Runtime To Use It With Printer.print Command?
Hi everyone,
I have a little application which uses printer.print command to do some print jobs, of course there are some other things that I print using Data Reports.
When my application starts, I think it instantiates printer object with the default printer (lx300). Once the application is started, there are some options that use printer.print, but there are options that use printer.print too but I need to print them in another printer (ip1000). I have a common dialog that lets me choose the printer, and when I choose ip1000 every printer.print call goes to lx300. I assume there's no way to "reinstantiate" printer object to print in ip1000.
Also, when I close my application ip1000 becomes my default printer. Does the common dialog can select a printer without changing the Windows default printer like Word, Excel. do?

Thanks a lot for your help

How Can I Change The Default Printer At Runtime To Use It With Printer.print Command?
Hi everyone,
I have a little application which uses printer.print command to do some print jobs, of course there are some other things that I print using Data Reports.
When my application starts, I think it instantiates printer object with the default printer (lx300). Once the application is started, there are some options that use printer.print, but there are options that use printer.print too but I need to print them in another printer (ip1000). I have a common dialog that lets me choose the printer, and when I choose ip1000 every printer.print call goes to lx300. I assume there's no way to "reinstantiate" printer object to print in ip1000.
Also, when I close my application ip1000 becomes my default printer. Does the common dialog can select a printer without changing the Windows default printer like Word, Excel. do?

Thanks a lot for your help

How To Change The Default Printer?
Hi brains


i am working in a accounting software, i don't know how i change the default printer in run time because i have a different page setup as default for different printer. i am using windows XP/sp2


pls help me .............................................................


with regards

annamalai

Change The Default Printer
I have two printers that have been setup in my computer. One is local and the other is in the network. My program needs to print in those two printers. How can I change the default printer of my computer? Im using vb6 in Windows 98 OS.

Change Default Printer
Hi again,

I want to know how we can change default printer through vb code ?

does anyone know about this stuff ?

Change Default Printer ?
Hello

I need to change the default printer
and then print something from a report.

but it keeps on ending up on the wrong printer.

I think i need to use API bud dont know how.

anybody ?

Thanks in advance
Micke

Change Default Printer In VB
Is there a way to change the default printer. One way suggested in Vb Help is to change the Printer.Device name to the specified printer and then use the set printer statement. But this just sends the output to that printer. I want to change the default printer in start/settings/printer also to show the default printer to the specified printer.
Is there a way in VB or is there an API to do this.
Thanks!

Change The Default Printer In VB 6
Hi!

I want to know how change the default printer through coding in Visual Basic 6.0 also how to set the path to save the PDF file.
I want to create a PDF file from a data report by chaning the default printer to "Acrobat Distiller" and after creating a PDF file the default printer should be changed to the previous one.
Please help me out because I am stucked in this.

Tushar

betrl8thanever: Moved to VB Newbies Forum



Edited by - betrl8thanever on 6/13/2007 9:31:23 PM

How To Change The Default Printer
Please let me know.

Thank you,

How Can You Change Printer From The Default?
How can you change printer from the default? Or print on another printer type \printserver1printer22

Please help

Ola A.

Change The Default Printer
I am developing an application which shows all the installed Printers in a Combo Box. The user depending upon his need selects the Printer from the Combo box and clicks on the Print button provided below. I want to Print to that Printer which the user have selected. But by default it always Prints to the default printer. I am using Printer.Print method for Printing.

Change Default Printer
Hi frients,

How can we change default printer by vb on windows 98?

Thanks,
C.P.Usman

Change The Default Printer
I need to change the default priner on the system

Change Default Printer
I have 2 printers on my computer. I can change default printer through Control Panel or from VB using Common Dialog. How to change default printer from VB code?
Thank you
Vlad

Change The Default Windows Printer?
Hi Everyone,

Is there a way to change the default windows printer using VBA in Access??

Thanks,
-Steve

Auto Change Default Printer
Hey guys, why always that i print something (using commondialogbox to select the printer), if the printer is not the default after the printing it will be. It change the computer settings to be the default printer. Any help would be apreciated.
Thanks
Eli

Change Printer Default Setting
how can i change the printer orientation settings without going into the printer dialog box?

Can't Change Default Printer.PaperSize (Please Help)
Hello everybody. I need to fill in and print out some Italian postal forms which are 33 cm long.

The default paper size set on Italian printers is A4, the length of which is only 29.7 cm, so I need to extend it by about 3 cm more or less.

I have set Printer.PaperSize = vbPRPSLegal, since the vbPRPSLegal constant should be equivalent to 35.6 cm but, in spite of this, the printing is truncated after 29.7cm.

Please consider that I compiled my form to an executable before testing the code but it did not work. Here is the incriminated code:


VB Code:
Private Sub Command1_Click()     Printer.ScaleMode = 7    Printer.Orientation = 2        Printer.PaperSize = vbPRPSLegal        Printer.FontName = "Verdana"    Printer.FontSize = 10        Printer.Print ""        Printer.Print "I would very much like this line to be printed out on a 21.6x35.6cm sheet of paper. Unfortunately, it looks like there's no way to change the default settings of my printer which do not want to exceed the 29.7cm height of an A4 page. I know for sure it does not depend on the model of my printer because I have installed someone else's VB6 program which manages to extend the length of the printable area. Why on earth doesn't it work?"        Printer.EndDoc End Sub


I would very much like to know what's wrong with the code above.

Any help will be greatly appreciated.

TIA

Change Printer Locally, Not Set As Default Win
I want an app to only change the printer default within the application. If I use the common dialog, I can set .defaultprinter=False to stop the Windows default printer from changing, but then my local printer isn't changed either!

Code:

Private Sub mnuFPrtSetup_Click()
cmdlg.PrinterDefault = False
cmdlg.Flags = cdlPDPrintSetup
cmdlg.ShowPrinter ' display Printer Setup cdlg box.
VPrint.DeviceName = Printer.DeviceName

End Sub

What can I do to change printers and not change windows defaults?

Change The Default Printer.URGENT!!!!
I'm new in the VB world, and I'm development an application that need change the default printer of the O.S, but without graphic interface.
Can someone help me, please???

Thanks in advanced

Change Default Printer Thru Code
I need to print a word doc. thru a VB application, but to a specific printer. So, I need to do the foll:

1. Change default printer to another, for WORD.
2. Print the specific doc.
3. Change printer back to default printer.

Can anyone help ?

VBScript To Change To System Default Printer
I'm trying to setup a script which will configure the printers on a PC. I've got the following sub's :

Code:
Sub InstallPrinter(PrintShare)
' Configure the Printer
Set WSHShell = CreateObject("WScript.Shell")

WScript.Echo "Connecting to Printer " & PrintShare
'Setup the printer connection

WSHShell.Run "rundll32 printui.dll,PrintUIEntry /ga /n" & PrintShare, 0, true

Set WSHShell = nothing
end sub
and

Code:
Sub SetDefault(DefaultPrinter)
'Sets the default printer to the argument supplied
On Error Resume next
Set objNetwork = CreateObject("WScript.Network")

WScript.Echo "Setting Default Printer to " & DefaultPrinter
objNetwork.SetDefaultPrinter DefaultPrinter

' Any other error, record the result
If Err.Number <> 0 thenWScript.Echo "Couldn't set the default printer (" & Err.Number & "): " & Err.Description

Set objNetwork = Nothing
end sub
The reason I've create the Printers using PrintUIEntry is because it allows me to setup a network printer globally. But then when I use the objNetwork.SetDefaultPrinter method it fails because the Printer doesn't exist. I've put a loop in there to wait for the printer to load... but after 5 minutes it still hadn't.

Is there something i'm missing... or a better way??

Thanks,

Cameron

Updated Code To Change Default Printer On XP ?
Hi,
   Have used code to change the default printer on NT, W2k no problemo, but am having an issue with XP. Does anyone have sample code that works for this on XP ?
Thanks, Steve.

Commondialog - How To Change Default Printer In VB6proSP5?
Can anyone please advise ... seems so simple .. yet ...
Environment is a single PC with three printers - ink jet, laser and postscript - on a switched LPT1. No problem there. But I am trying to change the default printer in VB to the user's printer selection - that doesn't work.

The user's selection changes in the commondialog dropdown but I can't see any property or simple means of finding out in code what it has changed to. And no matter what the user selects, the Printer.Devicename remains set to the pre-existing default printer name.

If I show a private VB6 printer select form - after .Showprinter (below) - and get the printer name that way, and replace Printer.Devicename in the comparison below, it works .. but there must be a better way? Can anyone help please.

             ' TEST SETUP of DEFAULT PRINTER ...

             Dim x as Printer
             With TN6Graf1
                     .CommonDialog1.Flags = cdlPDPrintSetup
                     .CommonDialog1.PrinterDefault = True
                     On Error GoTo CancelHandler
                     .CommonDialog1.CancelError = True
                     
                     .CommonDialog1.ShowPrinter
                                  
                     ' compare user's Printer Name selection and set as default printer

                     For Each x In Printers
                          If x.DeviceName = Printer.DeviceName Then
                               Set Printer = x
                               ' success
                               Exit For
                          End If
                     Next
             End with

             Printer.EndDoc


Thanks a lot .....


Fred Playne

Change Default Printer Setting At Runtime
could anybody give me a sample code to change the default printer's setting (paper width/height,paper source, orientatio) at runtime

How Do I Get Print Dialog To Not Change Default Printer?
Is it possible to use the Print Dialog to select a printer without the current default printer being changed to whatever is selected?

I would like to use the print dialog to allow a user to select a printer. Then use this printer and the print object to print to this printer. I do not want the current default printer to be changed? It seems to me other programs such as Word and Excel do this is it possible in VB?

Do I have to restore the default printer with something else after using the dialog?
I have seen ways to set the default printer and I think I have read in some places that to get the current printer selection from the dialog the default printer has to be changed, but is there another way to get printer selection and settings without changing the default printer?

Here is my code to show the print dialog and print.

With dlgCommonDialog
.DialogTitle = "Print"
.CancelError = True
.Flags = cdlPDReturnDC + cdlPDNoPageNums
If Err <> MSComDlg.cdlCancel Then
Call Print_DR1
End If
End With

Any help would be greatly appreciated!!!!

Change Default Printer's Paper Size At Runtime
could anybody give me a sample code to change the default printer's setting (paper width/height,paper source, orientation) at runtime

Crystal Reports Won't Accept Change To Default Printer
(VB6, Crystal 9)

I've added all the printers on the computer to a combobox, so the user can select a printer to print from.

I'm using a method i found on this forum, to change the default printer - it stores the default printer, sets the newly selected printer as the default, then re-instates the old default printer. ( I could paste this code, but its a bit lengthy - its the class thats a modification of MSDN's article Q167735).

So i have a custom print dialog, and under the print button i have (where setprinter is the lengthy class):

Dim SetPrinter As New clsSetDefaultPrinter
Dim DeviceName As String
Dim smsg As String

DeviceName = cboPrinter.Text
If SetPrinter.SetPrinterAsDefault(DeviceName) Then
smsg = DeviceName & " -set"
Else
smsg = DeviceName & " -not set "
End If

MsgBox smsg, vbDefaultButton1, ""

MsgBox Printer.DeviceName & vbCrLf & Printer.DriverName & vbCrLf & _
Printer.Port, vbDefaultButton1, ""

MyReport.PrintOut False, 1, False

'destroy instance of printer class to restore printer to default
Set SetPrinter = Nothing

MsgBox Printer.DeviceName & vbCrLf & Printer.DriverName & vbCrLf & _
Printer.Port, vbDefaultButton1, ""
End Sub


See the messageboxes - they show that the default printer is indeed being changed, then restored. Yet the report is still being printed from the "default" printer - that is, its prints like the change never took place, from the original printer, not the newly selected printer.

Now whats most frustrating about this is if i run the above code in a seperate .exe, (a simple combo box which lists printers, and does the above swapping of printers), leave it open after i've changed it to the printer i want, then open the app with the above code in it, it WILL print to the printer that i want to change it to.

I've tried adding the MyReport.PrintOut :

MyReport.SelectPrinter Printer.DriverName, Printer.DeviceName, Printer.Port

But this crashes the app and shuts down vb.

Can anyone help me, i'm getting a bald patch where i'm scratching my head so much.

Common Control Change Permantaly The Default Printer
I open a common Control box for user to select the printer to use. Everything goes ok for the printing. The problem is that the printer selected stuck as the default printer even after the program is closed. Here's my code :

comPrinter.CancelError = True
On Error GoTo ErrHandler
comPrinter.ShowPrinter


[Here I call function that set font, font size, and margins]
[Then I print using Printer.Print "text" followed by Printer.EndDoc]


Unload Me
Exit Sub
ErrHandler:
' User pressed Cancel button.
Exit Sub


I'm under visual basic 5, using comdlg32 version 6.0 under Win XP pro.

Thanks a lot for your help

Printing Forms Needs To Change Default Printer Setting
 I have created a Form in XLS which i need to print to a label printer located on USB port. The problem is to print a Form you can only print to the default printer. Which is my A4 printer on a network.

I have found examples to open a listbox and change in another form but this shows local printers only.

- I need to read the current printer (on network) and save as valiable (NWPrinter)
- I need to change the default Printer (on USA)
- I need to printform
- I then need to revert back to NWPrinter otherwise all the documents come out on the label printer.

Can anyone help? i need this from an VB in Excel. Thanks

Change Default Printer Before Using Shell Execute To Print Pdf Dicuments From Excel
hi
I have made program that prints pdf documents from excel using shell execute command. Since I have to print documents differently I have to change the printer to which I send the documents during the run time.
So can anyone tell me how to change the default printer in vba excel. shell execute function only prints to the default printer. Therefore I need to change the default printer.

bye

How Do I Make My Sub Routine Not Change My "default Printer"?
Hey people. I have this little program in MS Word that imports data in ASCII text file formats it a special way for this specialized printer. I then click on the print button (which I made) which activates the following sub routine. I do want the job to print on the "Pitney Bowes W790" as listed in the active printer line, but this changes my default printer settings in Windows Operating System. So the next time I print anything it chooses the default (which is Pitney Bowes 790). That is no good because all that printer does is print evelopes and post cards. It can't print regular paper.

***************************************************
Private Sub printCurr_Click()
'this prints the currently loaded form
ActivePrinter = "Pitney Bowes W790"
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=False, PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0

End Sub
***************************************************

I tried insert a line right before the "End Sub Line" that says ActivePrinter= HP LaserJet, but that made the sub routine crash.

Any help would be appreciated.

Thanks!

Chad

Vb/crystal:how To Replace Crviewer Default Printer With Windows Common Dialog Printer
hi all,
I'm trying to create a crystal report through vb.
does anyone know how to replace the default printer ( that comes with crviewer control) with a windows common dialog printer. I mean, with the options to select differnt printers etc.

Set Default Paper Size For Default Printer ...
So, hope that someone could help me..hix..
If i cant do this i will loose my job, my boss say so. I have to print a webpage with the size of paper is A5 baut the default always is Letter, hix, I could change it by hand but the users may not. So i want to set the default paper size of default printer to A5.
Thanks a lot.

VB6 - Print A Text File To A Remote Printer And My Default Printer
Please how can I get a text file located in my hard drive (C:) to print to my default printer and also print to a Remote Printer?

The remote printer is named "U288".

Any workable code snipet will be appreciated.

Thanks y'all.

Giftx.

Changed Default Printer But Job Goes To Old Default...
I have a print command with the following code:

Code:
Private Sub cmdPrint_Click()
Dim tmpPrinter As Printer
Dim DefaultPrinter As Printer

Set DefaultPrinter = Printer ' Save the default printer

For Each tmpPrinter In Printers
If tmpPrinter.DeviceName = cmbPrinters.Text Then
Set Printer = tmpPrinter
Exit For
End If
Next tmpPrinter

CrystalReport1.ReportFileName = FileIn.Path & "" & FileIn.FileName
CrystalReport1.Destination = crptToPrinter
CrystalReport1.PrintReport

MsgBox "Your report was printed"

Set Printer = DefaultPrinter ' Change back to default printer
End Sub
where the combo box is populated by this code:

Code:
i = 0
For Each InstalledPrinters In Printers
cmbPrinters.AddItem InstalledPrinters.DeviceName
i = i + 1
Next InstalledPrinters
cmbPrinters.ListIndex = 0
I select a printer (not the default printer, but a different one) from the combo list, then click on Print and the job is still going to the original default printer. Stepping through the code, I can see how Printer changes (to the printer I selected) during the execution, but the job keeps going to the old default printer. Also the last line of code in the cmdPrint_Click sub gives me a "Run-time error '13': Type mismatch" error.
What am I missing? Can anyone help please?

Thanks,
poli

How To Printer.Print To Non Default Printer

I have a small app that I need to modify.  Basically it sends a report straight to the (default) printer by Printer.Print

Users want to print to their non-default printer, too.  I could change the default printer by Set Printer = another Printer and then get back to the original one, but is there a better way to do it?
Have fun.

---- Andy

Changing Paper Size In Cdl.ShowPrinter Won't Change Printer.width And Printer.height
Hi,
I use this code to let the user change the paper size and orientation before printing.


VB Code:
CommonDialog.ShowPrintermsgbox printer.width & " " & printer.height 'print code here ...  


but under Windows XP even when I change the paper size from the dialog the vb's printer.width and printer.height arn't changed ....

Is there a better way to change the paper size .. and to retrieve the changed paper size ?

Printer.Height And Printer.Width Refuse To Change!
i'm using vb 6 and win xp. basically, no matter what value i set to printer.height and printer.width makes any change. check out my code, i'm probly doing something real dumb:


Label1 = Printer.Width 'gives value of 12240
Printer.Width = 6 * 1440 '6 inch Width x 1440 twips per inch
Label2 = Printer.Width 'gives value of 12240


i've tried various values, not just 6 *1440; none work. the papersize value does hower change from 1 to 256, which makes sence, but neither the width nor the hieght budge.

any ideas on why this happens, and how to fix it?

thx

How To Change Printer Orientation Specially For Dot Matrix Printer?
I want to konw API to change Printer Orientation? How to do it?

Change Printer Name In Printer Dialog Using API In Runtime
Hi all,

My default printer is kyosera 1000. I use following code to select the printer from a print dialog in external application:
Code:
hMain = FindWindow("#32770", "Print")
hChild = FindWindowEx(hMain, 0, "ComboBox", vbNullString)
nret = SendMessage(hChild, CB_FINDSTRINGEXACT, 0, "Kyosera 2500")
If nret <> -1 Then
'To select the printer in combo
Call SendMessage(hChild, CB_SETCURSEL, nret, 0)
End If
The above code selects Kyosera 2500 without any issues. but prints on Kyosera 1000 which is my default printer.

post your suggestions.

Default Printer
I have a network computer with a printer attached to lpt1 that I use for printing. The problem is, since the computer uses a dynamic ip I have to reconnect to the printer every time the computer restarts, it uses one of three ip addresses ( since there are three computers on the network). I have tried connecting to the printer by the computer's name, but this doesn't work. Can a small app be written to check and see if there is a printer attached to a network computer and if it's there set that printer as the default? I think I need a winsock control to "ping" the computer and if there's a response to set the printer to the default. Can this work, and if so, how can it be done/where can i learn how?

Thanks,
redrum

Set A Default Printer
Is it possible to programmatically change a default printer? How?

this is for VB6

Default Printer
I have two printers that have been setup in my computer. One is local and the other is in the network. My program needs to print in those two printers. How can I change the default printer of my computer? Im using vb6 in Windows 98 OS.

Help! How To Set Default Printer Using VB?
I have 5 printers connected to my machine, and I set Printer(2) as default in system's Control Panel, now I want to print the data report to different printer, so I try to change printer using following VB code:

private sub command1_click()
Set rsPrinter = New Recordset
strSql = "select * from PPRINTERSITE where SITEID = '81';"
rsPrinter.Open strSql, g_dbConn, adOpenKeyset, adLockOptimistic
If Not rsPrinter.EOF Then
For Each prt In Printers
If prt.DeviceName = rsPrinter("PRINTERNAME") Then
MsgBox "Printer is " & prt.DeviceName
Set Printer = prt
Exit For
End If
Next
End If
dataReport1.PrintReport
end sub

though the message from MsgBox told me the Printer already changed to other printer ( such as Printer(0) ), but the dataReport1 still be printed in Printer(2), Can someone help me?

Thanks

Yinghong

Default Printer
Hi all, is there a way to use vb code to set the default printer to print a crystal report w/i vb? Currently there is no way to change the default printer from the crystal report (crviewer)....please help..thanks!

Get Default Printer
Hi,
I want to find an API functions that tells me the name of default printer installed on my computer. 'Printer' object from VB is not enought for what I need.
Thanks
Lucian

Add Default Printer
I need to know how to add printers (including the default) to a Windows 2000 workstation using Visual Basic code. I want to automate the process instead of manually adding. Does anyone have any code that I could use? Thanks!

Default Printer
i have a small program that basically copies information from a flex grid into excel. however, i've found that the page setup properties are not active if there aren't any printers installed.

my question is what's the best way to check for installed printers? i tried an if statement: if printer.devicename = "" then don't do the page setup properties, but i still get the error 'Problem getting printer information from the system. Make sure the printer is set up correctly.'

any thoughts?

thanks,
jb

Copyright © 2005-08 www.BigResource.com, All rights reserved