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




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




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

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

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.

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

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.

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

Print To A Non-default Printer
I have a network printer installed on a print server. From my workstation, using a simple VB program, I'm trying to print to this printer. The printer is not my Default (in fact is not even shared on the server!). When I'm running this code:
Code:
Dim thePrinter As Printer
thePrinter.DeviceName = "\SERVERPrinter1"
Set Printer = thePrinter
I'm getting a "Compile error: Wrong number of arguments or invalid property assignment". Can anyone point out why it's not working?
Thanks,
poli

Print To Non-default Printer
I have a label-printing program that I want to print to a non-default printer. Each label is printed using "PrintForm". I do not want my user to have to change the setting for the default printer each time she needs to print a label.

What is the simplest way to change the printer in code?

Thanks in advance.

Print In The Default Printer From VBA.
I am developing a VBA embeded code in an Excel workbook and I would like that it send some phrases to be print by the default printer after the user click a button. If I am not confused, I remember that very old versions of Basic used to have the LPrint command but it seems that VBA does not support this command. Is there some equivalent command??

Print To A Non Default Printer
I currently have two systems. Each has a VB application that gets run on a schedule to print a data report to the default printer without any user interaction. I am tasked with combining these two older systems into one bigger system. Of course the problem is that I cannot have two default printers...and I cannot use the Print Dialog as there is no user interaction. Does anyone have a direction they can point me, sample code, etc...that would give me insight in how to tell a Printout to go to a specified printer. I would rather not have the code change the default printer, as a timing issue will come into play as I move more systems onto this same big server.

Default Printer Not Getting Changed In Runtime
The following code is used to change the default printer. I call WinNTSetDefaultPrinter with the printer name which I want to make default.
In design time, the change is getting reflected and my application uses the new default printer to print. But in runtime, the default printer is not getting changed. The old printer is getting used.

I am Shelling a Batch file, which inturn runs my application. Does this has any thing to do with such a behaviour?




VB Code:
Option Explicit Public Const HWND_BROADCAST = &HFFFFPublic Const WM_WININICHANGE = &H1APrivate Const WM_SETTINGCHANGE As Long = WM_WININICHANGEPrivate Const SMTO_NORMAL As Long = &H0  ' constants for DEVMODE structurePublic Const CCHDEVICENAME = 32Public Const CCHFORMNAME = 32 ' constants for DesiredAccess member of PRINTER_DEFAULTSPublic Const STANDARD_RIGHTS_REQUIRED = &HF0000Public Const PRINTER_ACCESS_ADMINISTER = &H4Public Const PRINTER_ACCESS_USE = &H8Public Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or _PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE) ' constant that goes into PRINTER_INFO_5 Attributes member' to set it as defaultPublic Const PRINTER_ATTRIBUTE_DEFAULT = 4 ' Constant for OSVERSIONINFO.dwPlatformIdPublic Const VER_PLATFORM_WIN32_WINDOWS = 1 Public Type OSVERSIONINFO    dwOSVersionInfoSize As Long    dwMajorVersion As Long    dwMinorVersion As Long    dwBuildNumber As Long    dwPlatformId As Long    szCSDVersion As String * 128End Type Public Type DEVMODE     dmDeviceName As String * CCHDEVICENAME     dmSpecVersion As Integer     dmDriverVersion As Integer     dmSize As Integer     dmDriverExtra As Integer     dmFields As Long     dmOrientation As Integer     dmPaperSize As Integer     dmPaperLength As Integer     dmPaperWidth As Integer     dmScale As Integer     dmCopies As Integer     dmDefaultSource As Integer     dmPrintQuality As Integer     dmColor As Integer     dmDuplex As Integer     dmYResolution As Integer     dmTTOption As Integer     dmCollate As Integer     dmFormName As String * CCHFORMNAME     dmLogPixels As Integer     dmBitsPerPel As Long     dmPelsWidth As Long     dmPelsHeight As Long     dmDisplayFlags As Long     dmDisplayFrequency As Long     dmICMMethod As Long        ' // Windows 95 only     dmICMIntent As Long        ' // Windows 95 only     dmMediaType As Long        ' // Windows 95 only     dmDitherType As Long       ' // Windows 95 only     dmReserved1 As Long        ' // Windows 95 only     dmReserved2 As Long        ' // Windows 95 onlyEnd Type Public Type PRINTER_INFO_5     pPrinterName As String     pPortName As String     Attributes As Long     DeviceNotSelectedTimeout As Long     TransmissionRetryTimeout As LongEnd Type Public Type PRINTER_DEFAULTS     pDatatype As Long     pDevMode As Long     DesiredAccess As LongEnd Type Declare Function GetProfileString Lib "kernel32" _Alias "GetProfileStringA" _(ByVal lpAppName As String, _ByVal lpKeyName As String, _ByVal lpDefault As String, _ByVal lpReturnedString As String, _ByVal nSize As Long) As Long Declare Function WriteProfileString Lib "kernel32" _Alias "WriteProfileStringA" _(ByVal lpszSection As String, _ByVal lpszKeyName As String, _ByVal lpszString As String) As Long Declare Function SendMessage Lib "user32" _Alias "SendMessageA" _(ByVal hwnd As Long, _ByVal wMsg As Long, _ByVal wParam As Long, _lParam As String) As Long Declare Function GetVersionExA Lib "kernel32" _(lpVersionInformation As OSVERSIONINFO) As Integer Public Declare Function OpenPrinter Lib "winspool.drv" _Alias "OpenPrinterA" _(ByVal pPrinterName As String, _phPrinter As Long, _pDefault As PRINTER_DEFAULTS) As Long Public Declare Function SetPrinter Lib "winspool.drv" _Alias "SetPrinterA" _(ByVal hPrinter As Long, _ByVal Level As Long, _pPrinter As Any, _ByVal Command As Long) As Long Public Declare Function GetPrinter Lib "winspool.drv" _Alias "GetPrinterA" _(ByVal hPrinter As Long, _ByVal Level As Long, _pPrinter As Any, _ByVal cbBuf As Long, _pcbNeeded As Long) As Long Public Declare Function lstrcpy Lib "kernel32" _Alias "lstrcpyA" _(ByVal lpString1 As String, _ByVal lpString2 As Any) As Long Public Declare Function ClosePrinter Lib "winspool.drv" _(ByVal hPrinter As Long) As Long Private Declare Function SendMessageTimeout Lib "user32.dll" Alias "SendMessageTimeoutA" _(ByVal hwnd As Long, ByVal msg As Long, _ByVal wParam As Long, ByVal lParam As Long, _ByVal fuFlags As Long, ByVal uTimeout As Long, _ByRef lpdwResult As Long) As Long  Public Sub WinNTSetDefaultPrinter(PrinterName As String)    Dim Buffer As String    Dim DeviceName As String    Dim DriverName As String    Dim PrinterPort As String    Dim r As Long    If PrinterName <> vbNullString Then        ' Get the printer information for the currently selected        ' printer in the list. The information is taken from the        ' WIN.INI file.        Buffer = Space(1024)        r = GetProfileString("PrinterPorts", PrinterName, "", _            Buffer, Len(Buffer))         ' Parse the driver name and port name out of the buffer        GetDriverAndPort Buffer, DriverName, PrinterPort            If DriverName <> "" And PrinterPort <> "" Then               SetDefaultPrinter PrinterName, DriverName, PrinterPort               SelectPrinter (PrinterName)           End If    End IfEnd Sub  Public Sub SelectPrinter(NewPrinter As String)    Dim Prt As Printer    For Each Prt In Printers        If Prt.DeviceName = NewPrinter Then            Set Printer = Prt        Exit For        End If    NextEnd Sub        Private Function PtrCtoVbString(Add As Long) As String    Dim sTemp As String * 512, x As Long     x = lstrcpy(sTemp, Add)    If (InStr(1, sTemp, Chr(0)) = 0) Then         PtrCtoVbString = ""    Else         PtrCtoVbString = Left(sTemp, InStr(1, sTemp, Chr(0)) - 1)    End IfEnd Function Private Sub SetDefaultPrinter(ByVal PrinterName As String, _    ByVal DriverName As String, ByVal PrinterPort As String)    Dim DeviceLine As String    Dim r As Long    Dim l As Long    DeviceLine = PrinterName & "," & DriverName & "," & PrinterPort    ' Store the new printer information in the [WINDOWS] section of    ' the WIN.INI file for the DEVICE= item    r = WriteProfileString("windows", "Device", DeviceLine)        ' Cause all applications to reload the INI file:    l = SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, "windows")        'Tell all open programs that this change occurred.Allow each app 1 second to handle this message.    'Using This also just in case this helps. But....Still the problem persists    l = SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0, SMTO_NORMAL, 500, 0)    End Sub  Private Sub GetDriverAndPort(ByVal Buffer As String, DriverName As _    String, PrinterPort As String)     Dim iDriver As Integer    Dim iPort As Integer    DriverName = ""    PrinterPort = ""     ' The driver name is first in the string terminated by a comma    iDriver = InStr(Buffer, ",")    If iDriver > 0 Then          ' Strip out the driver name        DriverName = Left(Buffer, iDriver - 1)         ' The port name is the second entry after the driver name        ' separated by commas.        iPort = InStr(iDriver + 1, Buffer, ",")         If iPort > 0 Then            ' Strip out the port name            PrinterPort = Mid(Buffer, iDriver + 1, _            iPort - iDriver - 1)        End If    End IfEnd Sub

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

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

Print To A Special Printer Instead Of The Default
Hy,

Right now i print everything to the default printer. Ore i can place a dialog on the screen so the user can select a printer with the line below:

Call frmMain.dlgCommonDialog.ShowPrinter

But i like to print it not to the default printer but to a printer called Primo
Is that possible ? and how?

I use VB 6.0

Thanks a lot!

Need To Print To A Specific Non Default Printer
I have written an app that prints barcodes from a SQL db via a GUI. When the user prints the barcodes, I want the barcode to automatically print to a printer I specify via an INI file. I have everything else working. The app currently open the printers box so the user can select which printer to print to, num copies etc.

How do a specify in my code the printer I want to print to without prompting the user with the printers dialogue?

Much Thanks,

Dave

DataReport Print Not In Default Printer
I have this problem: on my pc there are 2 VB application each with the DataReport.
The first, print on the default printer, the second must print on another network printer.
I found much example to set a printer like default printer , but I need to select from code the printer.

The print request is an asynchronous event and so i can change the defualt printer because there is the risk to create error.

If I show the report, is possible to select the printer (with the printer dialog). I need to make the same thing from code.

Help me please!!!
Thanks

&lt;RESOLVED&gt;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..

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 ?

Print A Form In Specific Printer (not To The Default)
I have more than 3 printer drivers installed in a machine.
Let say that the DEFAULT printer name is : hp deskjet 845c
I made a program that prints some barcodes with a SATO
driver, printer name is : SATO M-8400RV

Everytime I have to print, I have to change the default
printer and then print the barcodes or on the other hand
change the default again to print with the HP 845c.

How can I print a form in a SPECIFIC printer without having
to do that stupid manual thing ? I just use the form1.printform
command to print and works fine for the work to be done. I just want to
avoid that...change default all the time.

Default driver name : hp deskjet 845c
Barcode driver name : SATO M-8400RV
Default is connected with LPT1 and SATO with LPT2 (in printer settings)

Thanx a lot for your time.

Set Printer Defaults For Print Job And Return To Default
In a VB 6 application run in Win XP with Crystal Reports 9 RDC for reporting, the printer I am using for a specific print job allows duplex printing. I've included a printer selection button on a form for setting print parameters and allowing the user to select a specific printer and set up for the print job, using the CommonDialog control. The user then selects the printer and sets the duplex mode, then closes the printer setup dialog and sends the job to the printer. The duplex setting that was selected from the common dialog control is not carried over for the printout, instead the selected printer's default settings are used, ie, I can select the printer from the common dialog control, but not set the printer settings including duplex.

According to MSDN's web site the printer object and the CommonDialog control do not share information. MSDN recommends using the PrintDlg to change the settings for specific print jobs and provides a downloadable PrintDlg.dll. I downloaded this dll and used the sample code. When checking the printer settings prior to sending the job to the printer, the duplex setting is as selected from the printer dialog. But again, when the job is actually printed, the duplex mode is set at the default. Again, I am able to select the printer, but not the settings.

I found the attached code which allows me to change the default settings using API calls and works fine for changing the settings and having my print job print properly. But this does change the default settings. I want to be able to change the settings back to the original default. In MSDN help on DevMode, "to reset the default to the global default DEVMODE, call SetPrinter with the Printer_Info_8 structure." There is no code example on how to do this. How would I return use Printer_Info_8 structure to return the printer to original default settings? Or does anyone have a better method of changing the printer settings (such as duplex) for an individual print job.

Print On Network Printer (default) Not Working
Hello,
I have a local printer installed (that is not the default printer) and a network printer that is the default.
If I send a report to print using datareports, printing is correct, but if I send something to print using the printer.print then nothing is printed.
The job is sent to the local printer instead!
I´ve read that VB is supposed to send whatever to the default printer... why then isn´t it working for the printer.print?
I need to print always to the default printer.

How To Set Default Printer In PDF And Print PDF One Page At A Time
How to set default printer in PDF and print PDF one page at a time

The code below will print a PDF file to a tiff converter driver "PEERNET.DRV ePro 5.0" but I am prompted for a filename (a TIFF file) to print to.
I can only do this after setting "PEERNET.DRV ePro 5.0" as the default printer through the printer panel.

What I want is to be able to set the default printer programmatically, print all pdf file pages to individual TIFF pages (with individual names of course).

Lastly, reset the printer back to the original default printer.


(what is not declared here should be considered to be global)
Private Function GetImageFromPdf(strDirName As String, _
astrDestFolderName As String, _
astrFileName As String, _
strFileNameStem As String, _
imageType As String)

Dim fileFullPath As String


Dim AcroExchAVDoc As Object, AcroExchPDDoc As Object, _
AcroExchApp As Object

'Dim fileFullPath As String ', strPath As String
Dim iNumberOfPages As Integer

On Error GoTo HandleError

Set AcroExchApp = CreateObject("AcroExch.App")
Set AcroExchAVDoc = CreateObject("AcroExch.AVDoc")
Set AcroExchPDDoc = CreateObject("AcroExch.PDDoc")


' must restore remed out for debugging multiselect
' when we open the file it will return true/false
fileFullPath = strDirName & "" & astrFileName

'openResult = myPDFPageCount.Open(fileFullPath)

' Open the [strFileName] pdf file
' AcroExchAVDoc.Open strPath + strFileName, ""
AcroExchAVDoc.Open fileFullPath, ""

' Get the PDDoc associated with the open AVDoc
Set AcroExchPDDoc = AcroExchAVDoc.GetPDDoc

'SavePrinter = App.ActivePrinter ' works for MS Wordl for windows
' vbPRPSLegal is a constant for 8 1/2 x 14 in legal size
Printer.PaperSize = vbPRPSLegal

'AcroExch.avdoc.PrintPages 0, pddoc.GetNumPages - 1, 1, False, False

‘AcroExchApp.ActivePrinter = "PEERNET.DRV ePro 5.0" ‘ BBBOOOOOMBS

'Note The first page in a document is page 0 for OLE automation.
' from http://csis.pace.edu/~anderson/AIS/art1.html
For pagenumber = 0 To pageCount - 1

' Print all pages in this document
'AcroExchAVDoc.PrintPages 0, iNumberOfPages, POSTSCRIPT_LEVEL, True, False
AcroExchAVDoc.PrintPages pagenumber, pagenumber, POSTSCRIPT_LEVEL, _
True, False

DoEvents
Next

' Close this file
AcroExchAVDoc.Close True

End Function

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

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.

Print File To Non Default Printer Without User Intervention
How can I print I file to a specific printer, without user intervention?

My first option was this

Code:
.
.
.
Open fileName For Input As #1
Printer.FontName = "Courier"
Printer.FontSize = 12
l = 0
While Not EOF(1)
Line Input #1, str
Printer.Print str
l = l + 1
If l = 56 And Not EOF(1) Then Printer.NewPage
Wend
Printer.EndDoc
Close (1)
.
.
.
But it prints to the default printer


Code:
.
.
.

Open filepath & "SISIMinvPrt.bat" For Output As #1
Print #1, "NET USE LPT1: /DELETE"
Print #1, "NET USE LPT1: " & invPrinter
Print #1, "Copy " & Chr(34) & Replace(fileNames, ",", Chr(34) & " LPT1" & vbCrLf _
& "NET USE LPT1: \sia2LEXMARKC" & vbCrLf _
& "Copy " & Chr(34)) & Chr(34) & " LPT1"
Close #1
Shell Chr(34) & filepath & "SISIMinvPrt.bat" & Chr(34)
.
.
.
The code above works partially
fileNames contains all files to be printed separated by a comma

The problem is that after printing the first file the rest of the files dont start at the top.

Print Dialog - Problem Resetting Printer To Default
I'm using the API to bring up a print dialog and return info from the dialog (I got the code off AllAPI.net). I then want to set the printer to the selected print dialog printer without changing the default. The code below works fine:

NewPrinterName = UCase$(Left(DevMode.dmDeviceName, InStr(DevMode.dmDeviceName, Chr$(0)) - 1))
If Printer.DeviceName <> NewPrinterName Then
For Each objPrinter In Printers
If UCase$(objPrinter.DeviceName) = NewPrinterName Then
Set Printer = objPrinter
'set printer toolbar name at this point
End If
Next
End If
At this point, the printer.devicename is the same as that just set from the print dialog. However, I also want to run the following lines of code...


On Error Resume Next
'Set printer object properties according to selections made
'by user
Printer.Copies = DevMode.dmCopies
Printer.Duplex = DevMode.dmDuplex
Printer.Orientation = DevMode.dmOrientation
Printer.PaperSize = DevMode.dmPaperSize
Printer.PrintQuality = DevMode.dmPrintQuality
Printer.ColorMode = DevMode.dmColor
Printer.PaperBin = DevMode.dmDefaultSource

...but as soon as I execute the "Printer.copies = ..." statement, the Printer and Printer.DeviceName are reset to the default.

Any ideas why this is happening? I'm still running VB5.

How Can I Print A Web Page Using Controls With Non-default Printer Settings
How can I print a web page using controls with non-default printer settings:

- I want to set the number of copies so, that the user won't be able to modify it.
- And I want to specify the printer that will print out the HTML document

Please help me, I need the answer! Thanx!

How Can I Print A Form Or Rapport From A Printer Who&#8217;s Not Are The Default?
How can I print a form or rapport from a printer who’s not are the default? I don’t wont to change the default printer to another, I wont to use a printer I chose in a list who presents the printers who are in windows printer list. It’s nice if it works in Access 2000 or VB 6.

Help please

Ola A.

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