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




Changing The Default Printer


On a form used to print reports I offer a Printer Setup button where the user can change to a different printer before printing the report. The problem is that when the user changes to a different printer, the Windows Default print is changed as well. Is there a way to only change the current printer for the session without changing the Windows default printer?

Current setting:

cmd.Flags = cdlPDPrintSetup
cmd.ShowPrinter




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Changing The Default Printer On A P.C
Don't ask, it's my week for nutjob requests.

Have a printer name, and need to change the printer.devicename to that name I think, but can't get it to work. Seems doing it manually is a bit beyond some people.

Off to bang head against desk

Changing The Default Printer
This has to be simple, but I am missing it.
How can I change the default printer. I need to be able to print to a specific printer for the first of 2 prints.

Thanks
Bill

Changing The Default Printer
HI ,
any one know how to change the default printer using VB code...

Windows Default Printer Changing
On a form used to print reports I offer a Printer Setup button where the user can change to a different printer before printing the report using the common dialog box. The problem is that when the user changes to a different printer, the Windows Default print is changed as well. Is there a way to only change the current printer for the session without changing the Windows default printer?

Current setting:

cmd.Flags = cdlPDPrintSetup
cmd.ShowPrinter

Changing Default Printer Settings
New to this group and I appreciate any help.
I need to print a vb form on a Zebra Label printer. However, the Zebra settings are frozen at 2x3 inches and this is not large enough for my form. I have not worked with printing from vb before and need to know where (and how) I code settings to send to the printer along with my data. The size of my form does not seem to affect the printer and when I print to my Cannon the default(letter size) is large enough to accomodate my form. So what objects and properties do I set and where do I place this code to overide Zebras default. I know Zebra settings can be overidden as another program accomplishes this however this other program(Bartender) is not appropriate for this app.Thanks for your time BradC

Problem In Changing Default Printer!
Hi !
I am trying to convert an Ms Access report to PDF in order to send it as attachement in my E-mail ... I completed this task succesfully by providing a virtual printer that prints to a file.pdf .

So in my code I am:
1- switching to PDFPRINTER
2- sending the attachment
3- switching back to the "real" default printer

this task is done succesfully : in the control panel I can check that the default printer is being set after sending the message .

The problem occurs when I try to perform an ordinary print of the report,(before restarting the application) in the pagesetup I can notice that the printer doesn't change back to the default printer and the default printer shows that it remains PDFPRINTER although it changed in the controlpanel !

I don't know if there is a way to refresh the setting in page setup without restarting the application ANY IDEAS !?!??!?!

please help !
                                        Anis

Dynamically Changing The Default Printer
I am trying to write VB 6.0 code to dynamically change the connected network printer in Windows XP.
The operating system essentially ignores the following method

Set xlApp = CreateObject("Excel.Application")
xlApp.ActivePrinter = "MAINT_HPLJC5500_Q"

I have found some Visual C++ code to create a DLL but can this be accomplished within VB6?

Changing Default Printer Through A Script
I would like to write a script to change the default printer.

I know that the default printer is stored in the registry here:

HKey_Current_UserSoftwareMicrosoftWindowsNTCurrentVersionWindowsDevice

The value for the device is "\FS1HP8000,winspool,Ne01:", but I want to change it to "\FS1PTX,winspool,Ne03:" and vice versa through a visual basic script.

Any ideas?

Please Help: Changing Windows Default Printer
Hello everyone,

Hopefully someone can help me with this. I need some VB code to change
the Windows default printer in Control Panel. I can't just change the
application default printer, I have to change the system default. I'm
not very conversant with API calls, so if that's the only way to do
this, I'd really appreciate some actual code or a reference to where I
can get some.

Thanks a lot,

Joe

Changing The System Default Printer
In VB, you can change the default printer by reassigning the Printer object. However, that only changes the default printer for that application. I am creating an Active X control to be used with other applications (such as Access) that allows changing the default printer. However, reassigning the Printer object no longer works. More precisely, it works inside the control, but not outside the control. The question is, how can I make the control change the system printer for the application using the control?

Here is an example to demonstrate what I'm talking about:

'the following is code inside the control
debug.print Printer.DevName 'displays name of default printer, "printer1"
set Printer = Printers(2) 'changes the default printer to printer number 2
debug.print Printer.DevName 'displays name of default printer, "printer2"
'now exit control code
'execute code of containing program, such as Access or a VB app
debug.printer Printer.DevName 'displays original printer name, "pritner1"




One solution for this is to change the default printer for the entire system. Users can do this manually (e.g., in the control panel), but I need to do it programmatically. Only I can't find an API for this. Anyone got a clue?

Changing Printer With Dialog Without Changin Default?
Hi.

I'm trying to use the commondialog.showprinter method to give the user of my program a choice for the printer when he prints a report.

Now my problem is that I do not want the default printer of the system to be changed by the dialog, so I set commondialog.printerdefault to false.

However, since I did that, it seems the application ignores whatever printer I selected in the dialog, and simply prints to the default printer.



Here's my code so far:

Private Function setup_impression()
Dim NbreCopies As Integer
Dim i As Integer

CommonDialog1.CancelError = True
On Error GoTo ErrHandler

CommonDialog1.flags = cdlPDNoSelection Or _
cdlPDNoPageNums Or _
cdlPDHidePrintToFile Or _
cdlPDUseDevModeCopies Or _
cdlPDReturnDC

CommonDialog1.PrinterDefault = False

CommonDialog1.ShowPrinter

Set Printer = CommonDialog1.hDC

NbreCopies = CommonDialog1.Copies
For i = 1 To NbreCopies
Call imprimer
Next i

ErrHandler:
Exit Function

End Function


The function imprimer has the printing code.

Changing Default Printer Settings (PaperBin)
The application I inherited has MS DataReports, which completely circumvents the Printer object in VB6.

I'm having to set the Default Printer through API calls then print to the reports. However, I need to be able to control the PaperBin, Some reports go to letterhead, some go to standard paper.

I've had no luck finding a way to control the paperbin of hte default printer.

By the way... when I manually change the paperbins in the windows printer settings, the settings work... I just can't figure out how to do this programmatically.

<RESOLVED>changing Default Printer At Runtime
hi everyone.. can anybody tell me how to change the default printer at runtime? its because, ive noticed that when using data report, it always uses the default printer when you print it.. i just want to use a specific printer when i print my report and change it again to its original default printer.. how can i do this without using the print dialog box? thank you..

Changing The Default Printer Settings Through Coding In VB
Hi All,
I have a problem in changing the default properties of the printer through Coding .Currently it is set to A4.But I want to change it to 5 cms * 15 cms.I have used the printer.print method.

I have also wriitten the code

With Printer
.ScaleMode=7
.height=5
.width=15
End With
But the Co-ordinates still gives me the height in Twips.
The operating system I am working is WIN XP.

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.

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

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.

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

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

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 ?

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 Printer Preferences With VB.Printer
I don't know if this has been posted or not but I've been goggling this subject for the past hour with no significant breakthrough.

I have a report that can only be displayed if the user's default printer is set to Landscape. Otherwise I get an error "Report Width is larger than the paper width". So I am trying to force the user's default printer to landscape mode. Through the watch window I can see that the following code does set the printer to landscape mode, but I still get the above mentioned error. And I can see through the control panel that the code didn't change anything on the printer. Is this a Privilages problem or do I need to save the changes somehow. OR, can I suppress/dupe the error from the standard report object?

Thanks...

-----------------------------------------------------------
Private Function ChangePrinterSettings()
Dim pntDefault As VB.Printer

Set pntDefault = VB.Printer
With pntDefault
If .Orientation = vbPRORPortrait Then
.Orientation = vbPRORLandscape
End If
End With
End Function
-----------------------------------------------------------

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

Which Is The Default Printer
I'm using the code below to change printer queues from one to the other. I need to know if the printer is the "Default Printer" before I change it. Here is the code I'm using: Thanks for the Help.

'******************************************************
'* File: ChangePrinter
'* Created: May 2003
'* Version: 1.1c
'*
'* Main Function: Changes Printer Paths
'* Usage: ChangePrinter.VBS \ServerNameOldPrinter \ServerNameNewPrinter
'*'****************************************************

'Get the command line arguments
if (Wscript.arguments.count > 2) or (Wscript.arguments.count < 2) then
wscript.echo "You put the wrong number of arguments you need to put 2. Put the old printer path first, followed by the new printer path. ex. changeprinter \hqptrz010500 \hqptrz010501"
WScript.Quit
end if

OldPrinterPath = Wscript.arguments.item(0)
NewPrinterPath = Wscript.arguments.item(1)

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections

For i = 0 to oPrinters.Count - 1 Step 2
If lcase(OldPrinterPath) = lcase(oPrinters.Item(i+1)) then
' Add the New Printer
WshNetwork.AddWindowsPrinterConnection NewPrinterPath

' Make the New Printer the Default Printer.
WshNetwork.SetDefaultPrinter NewPrinterPath

' Remove the Old Printer
WshNetwork.RemovePrinterConnection OldPrinterPath,true,true
End if
Next

Set WshNetwork = Nothing
Set oPrinters = Nothing
WScript.Quit

Set Default Printer OCX
Can't seem to put it into the code library but gonna put it here instead.

An ActiveX Combo To Find All Installed Printers and Specify The Default Printer.

Enjoy

Default Printer
Hi, I wish to get the device name of the default printer but VB's API does not do it. I did a search on the forum and found one thread, that thread has a link to another site about retrieving the default printer's device name but the site is no longer avaiable. Is there anyone that can help?

Default Printer
can anybody help me about how to use the windows default printer to print something? if there is a tutorial i think that will be best for me.

Default Printer
Well, seeing as this forum now includes "reporting" is suppose that this thread belongs here. If not, please feel free to move it.

How do I set the current printer to the default printer, having changed it to a not default printer?

P.S. I've searched a few returned entries in Google and none of them have the answer that I'm after.

Can't Set Default Printer
This is crazy. There are 2,000 topics on the default printer, but I still can't solve my problem. My program prints fine but I can't change the default printer.

I can't execute a simple command. Is there some component or reference I need in my program.

This gives me an "Object Required" error
TempString = "Canon Bubble-Jet BJC-265SP"
Set Printer = TempString

This is the code I want to use.


VB Code:
Dim strCurrentPrinter As String 'get current printer name and store itstrCurrentPrinter = Printer.DeviceName 'To set your printer as default printerSet Printer = "Your Printer Name" 'Do your codings to print Set Printer = strCurrentPrinter 'to set back the earlier printer as default  

Default Printer
How to get the default printer in my machine and also check the status and print a pdf file by vb?

Set Default Printer
I have searched for some help on this, but it is very vague and/or complex.

I need to retrieve the name of the default printer, change it to Win2PDF, do some printing and then change the printer back to the old default.

The system default printer is found at hkey_current_userssoftwaremicrosoftwindows ntcurrentversionwindows.

How can I read that name, change to Win2PDF and then change back again?

PS.- I am currently using a program called sdp.exe (Set Default Printer) and it is excellent, but if the user changes their printer, my program won't work properly.

VB Default Printer
It is my understanding that the VB printer is the default system printer and the object Printer will print to the system default printer. I use the following code to change the orientation to landscape

CommonDialog1.Flags = &H40
CommonDialog1.PrinterDefault = True
CommonDialog1.ShowPrinter

On completion of the CommonDialog1.ShowPrinter the orientation in the Printer object is still protrait.

What am I missing here??????

Default Printer
what is the simplest way to set a default printer with code?

VB Default Printer
I need help restoring the default printer to an original value. I have an application that uses PrinterDefault = True so when I change the printer, it marks it as default but I need to change the default back to it's original value.
Thanks...

Default Printer
Does anyone know how to check if a user has a default printer?

Default Printer
How would I retrieve the default printer on the system without using the Printer object. I'm trying to do this in Access??

Is there an API etc???

Thanks

Default Printer
How Would I retrieve the default printer in windows XP programmatically. In the previous version of Windows it was stored in win.ini.

Thanks,

Default Printer
Hi Guy's,

how do i change my default printer temporary to print a document and change back when I exit my visual basic application
thank you

Set Default Printer
Hi Everyone,

I have a piece of code that sets a specific printer to the default printer position based upon what printer the user selected from a combo box. The code works fine except for one problem. Once the new printer has been set as the default printer the code sends a broadcast message to all other programs to reload the INI file. When this happens sometimes the computer hangs or pauses until the user selects the Windows START button or some other command to get the broadcast to stop. What is causing this problem? Here is the line of code that program gets hung up on. I would appreciate any help. Thanks.


Code:

' Cause all applications to reload the INI file:
l = SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, "windows")

Default Printer??
how can i work out what printer is the default??

Getting The Default Printer
Alright, this should be easy... How do I retrieve the current default printer?

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