See Related Forum Messages: Follow the Links Below to View Complete Thread
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 ?
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 Default Printer
Hello!
i amn trying to add a Visuail basic 6 code to an excisting code that has the
purpose to change the current default printer to another printer by name and
then after the printer to change back to the old default printer again...
Anyone knows how to do this easy??
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
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
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
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
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
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
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
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!!!!
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
Set Printer As Default Through Code
Hi All,
i print reports checks and fill some preformated letters
I am using VB6.0 and Access97
when i print checks and Letters, i want to change the printer through code
i tried to change the printer as experintent
Code:
Private Sub cmdPrintChecks_Click()
Dim X As Printer, sPrinter$
sPrinter = "\Userq_mail-room2"
For Each X In Printers
If X.DeviceName = Trim(sPrinter) Then
Set Printer = X
Exit For
End If
Next
..............then print checks.
...........reset the default printer again.
End Sub
But it's not working. The printers are on network
can some body help me?
>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Edited by - sreddy on 9/13/2005 12:11:49 PM
Resetting Default Printer In Code
I am currently using VB6 with SP6 installed. I have the Component One add-on also installed. I am using the VSPRINT object to preview/print out a report. There are two basic types of printers that I use.
The two types are:
1 - 8 1/2 inch x 11 inch
2 - 3 inch Receipt Continious
I want to be able to set the default printer temporarily within code so that I can have the report program print to the appropriate printer needed by the specific report that is being requested.
I have this code already there
Public Function SetPrinter(ByVal DeviceName As String) As Boolean
Dim X As Printer
If Printers.Count > 0 Then
For Each X In Printers
MsgBox (X.DeviceName)
If InStr(LCase(X.DeviceName), DeviceName) Then
MsgBox ("Set " & X.DeviceName & " as default printer")
Set Printer = X
SetDefaultPrinter = True
Exit For
End If
Next X
End If
End Function
but even though it shows that the current device set is 8 1/2inch by 11 inch style printer when it goes to the preview it shows it as the default printer which in some cases is quite possible to be the 3inch receipt printer. Therefore if it is the 3inch style it does not display correctly and also when it is told to print it prints to the default printer even though the code above is set such that the default printer within the program should be the one with MAIN in its name which will be the 8 1/2 inch x 11 inch printer.
ANy suggestions or ideas?
Thanks in advance for your help in this.
Seasons Greetings & God Bless to you and yours.
My Code Always Prints To The Default Printer (Help)
This code works good except it only prints to the default printer. Can Someone Help me. It prints out a picture.
Private Sub Command2_Click()
On Error GoTo ErrHandler
MainFrm.CommonDialog1.Flags = cdlPDNoSelection Or _
cdlPDNoPageNums Or _
cdlPDHidePrintToFile Or _
cdlPDUseDevModeCopies
MainFrm.CommonDialog1.PrinterDefault = False
MainFrm.CommonDialog1.CancelError = True
MainFrm.CommonDialog1.ShowPrinter
Printer.Copies = MainFrm.CommonDialog1.Copies
Printer.Orientation = MainFrm.CommonDialog1.Orientation
Printer.Print ""
Printer.Print ""
Printer.Print Tab(12);
Printer.Print Label2.Caption
Printer.Print Tab(12);
Printer.Print Label3.Caption
Printer.PaintPicture Image1.Picture, 1000, 1000
Printer.EndDoc
Exit Sub
ErrHandler:
Dim RetVal As Integer
RetVal = MsgBox("Canceling Print Job", 0, "Printer ")
Exit Sub
End Sub
Thanks
Brandon
Change Text Box Default Language State From Code
Hello,
I am trying to make this simple operation without success: i have developped an application that runs under a localized windows(hebrew). And a text box which should get inputs in the localized language changes its state to english and backforth each time i show the form. Does some one know how could i set the text box to be (and to stay) in the localized language?
Thanks Alot,
Oran
Change Printer W/Code
I am trying to find a way to change which printer the program prints to. This will be automated and done w/o a user. Does anyone know of a way to set the printer in code w/o the printer dialog box? Please let me know ASAP.
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
CommonDialog1 - 'Change Printer' Code Only Works First Time Thru
My program allows the user to change printers before printing a report, and also displays the current printer name in a label on the form.
My problem is that my code only works the first time it is executed. ie The user changes from default Printer1 to Printer2, prints the report, then wants to change back to Printer1 again - my code doesnt work. The printer dialog comes up and LOOKS like the printer is changed back but my program still tries to use Printer2 and the label still displays Printer2's Name.
My code is as follows:
VB Code:
Private Sub btnChangePrinters_Click() CommonDialog1.PrinterDefault = FalseCommonDialog1.ShowPrinter LabCurrentPrinter.Caption = Printer.DeviceName End Sub
Many thanks
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.
CHANGE PASSWORD (updated Fields ON ERROR)
OK I've just launched a program that I've written and I ran into a really weird problem today.
One of the users tried to change his password today (new piece of functionality)
I use the sp_password to change the password, this allowed them to change the password, but when they continued on to update a field, the system gave a message of login failed! And they had to log out and get me to change their password back, but then I discovered that when this happened the field that we were trying to update, was updated with the information, but so were all the other fields in that column.
ie: in the field "Validated", we wanted to update one of them to -1 but when this happened they were all updated to -1, even though some of them had been 0.
Does anyone have any advice? Is this even possible?
Any comments would be greatly appreciated.
I know this is a VB Forum, I was just wondering if anyone else ever encountered a problem like this.
<Edit> breakfast3001 - I changed all those caps to normal letters ... No shouting please </Edit>
Edited by - breakfast3001 on 2/23/2005 2:29:00 PM
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 ?
Installation Of ONLY Updated Forms/code
Hi everyone!
I have an app that is going to a new sub version (i.e. from 1.1 to 1.2). I want to know if it is possible to setup a exe that only updates the forms and code that is new. Like when you get an upgrade disk for your commercial software. Any ideas out there?
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
|