473,563 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Print to user selected printer without changing it to default???

spider1916
9 New Member
I am using the common dialog control to allow my users to select any printer
available to them. The code I am using keeps changing the selected printer
to the default printer........ ....I don't want that.

I can't find anything with a propar salution to my problem.
I JUST WANT TO PRINT A REPORT!!!!!!!
No setting needs to be changed, ever. I only want to get the selected printer
from the dialog and print to it.

This seems to allow me to print to the selected printer but still sets it as
the default.

Expand|Select|Wrap|Line Numbers
  1.  
  2.     Dim X As Printer
  3.  
  4.     frmPO.comdPrintPO.ShowPrinter           
  5.  
  6.     For Each X In Printers
  7.  
  8.         If frmPO.comdPrintPO.hDC = X.hDC Then 
  9.  
  10.             Set Printer = X
  11.  
  12.         End If
  13.  
  14.     Next X
  15.  
  16.  
System Specs:

Win XP Pro
Windows Visual Studio98
Visual Basic 6.0

Please reply.......... ...really need some help
Thanks

Spider1916
Dec 5 '06 #1
9 27959
sashi
1,754 Recognized Expert Top Contributor
I am using the common dialog control to allow my users to select any printer
available to them. The code I am using keeps changing the selected printer
to the default printer........ ....I don't want that.

I can't find anything with a propar salution to my problem.
I JUST WANT TO PRINT A REPORT!!!!!!!
No setting needs to be changed, ever. I only want to get the selected printer
from the dialog and print to it.

This seems to allow me to print to the selected printer but still sets it as
the default.

Expand|Select|Wrap|Line Numbers
  1.  
  2.     Dim X As Printer
  3.  
  4.     frmPO.comdPrintPO.ShowPrinter           
  5.  
  6.     For Each X In Printers
  7.  
  8.         If frmPO.comdPrintPO.hDC = X.hDC Then 
  9.  
  10.             Set Printer = X
  11.  
  12.         End If
  13.  
  14.     Next X
  15.  
  16.  
System Specs:

Win XP Pro
Windows Visual Studio98
Visual Basic 6.0

Please reply.......... ...really need some help
Thanks

Spider1916

Hi there,

Kindly refer to below attached code segment for further understanding, it basically change the selected printer as default temporarily, hope it helps. Good luck & Take care.

Expand|Select|Wrap|Line Numbers
  1. Public Function SetDefaultPrinter(ByVal DeviceName As String) As Boolean
  2.     Dim prThis As Printer
  3.  
  4.     If Printers.Count > 0 Then
  5.         '\\ Iterate through all the installed printers
  6.  
  7.         For Each prThis In Printers
  8.             '\\ If the desired one is found
  9.             If prThis.DeviceName = DeviceName Then
  10.                 Set Printer = prThis
  11.                 SetDefaultPrinter = True
  12.                 '\\ Stop searching
  13.                 Exit For
  14.             End If
  15.         Next prThis
  16.  
  17.     End If
  18. End Function
  19.  
Dec 5 '06 #2
spider1916
9 New Member
Hi Sashi

Thanks 4 the reply and code....

Ok, so basically once the user has chosen a printer it should be set as the
default. Then I Print the report to that printer (which is now default).

Is it somehow possible to record the default printer devicename before the user
makes a selection and then after the report has printed reset the default printer
to that recorded devicename?? i.a.w. only make selected printer default until
report is printed and then (without user interaction) reset to previous default?

How would I go about getting the default printer name from the common dialog or whatever other place possible before user changes it?

Thanks again
Spider1916
Dec 5 '06 #3
DogsBollox
2 New Member
Hi Mate,
not sure if you still need help but....

a few years ago I struggled with this problem for weeks and eventually I wrote a small function that changes the default printer only for the job being sent, it is automatically changed back.

The code is now on PSC

http://www.planetsourc ecode.com/vb/scripts/ShowCode.asp?tx tCodeId=55941&l ngWId=1

if this does not work email and I will send it over
Jan 5 '07 #4
spider1916
9 New Member
Hi Mate,
not sure if you still need help but....

a few years ago I struggled with this problem for weeks and eventually I wrote a small function that changes the default printer only for the job being sent, it is automatically changed back.

The code is now on PSC

http://www.planetsourc ecode.com/vb/scripts/ShowCode.asp?tx tCodeId=55941&l ngWId=1

if this does not work email and I will send it over
thanx so so so so much

it worked like a dream, for a moment i thought i was imagining thing but no....
i was able to change it to fit my needs......

thanx again
spider1916
Jan 16 '07 #5
harrylarenson
3 New Member
thanx so so so so much

it worked like a dream, for a moment i thought i was imagining thing but no....
i was able to change it to fit my needs......

thanx again
spider1916

I have the same Problem , but I could not resolve it.
Would you please Write your code that you have solved the problem ?

When I am using the code for SetDefaultprint er Function still The default printer is keep changing as I select another printer in commondialog printer.

Thanks.
Apr 23 '07 #6
harrylarenson
3 New Member
I used The function as:

Expand|Select|Wrap|Line Numbers
  1. Dim defaultPrinter
  2.  
  3. defaultPrinter = Printer.DeviceName
  4.  
  5. SetDefaultPrinter (defaultPrinter)
but the default is not changing in VB 6.
Apr 23 '07 #7
Tecdec
1 New Member
Old Topic, but i got the same problem.. and solved with this:

Initial Code: Always change selected printer to default
Expand|Select|Wrap|Line Numbers
  1.     CommonDialog1.CancelError = True
  2.     CommonDialog1.ShowPrinter
  3.  
By default common dialog change selected printer to default.
Expand|Select|Wrap|Line Numbers
  1.     CommonDialog1.CancelError = True
  2.     CommonDialog1.PrinterDefault = False 'This Line Stop it!
  3.     CommonDialog1.ShowPrinter
  4.  
Apr 19 '12 #8
AmmarDev
2 New Member
hi,

i send you an email so you can give a solution?
May 31 '16 #9
mukilan89
1 New Member
Can you send me the code. The link is expired.
Aug 27 '18 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
3641
by: Alan | last post by:
While not rs.eof <td><%=rs("InvoiceNo")%></td> <td><%=rs("Name")%></td> <td><a href="InvoicePrint.asp?WInv=<%=rs("InvoiceNo")%>"></a></td> <td>Print this invoice</td> rs.MoveNext Wend Now user needs to click the link to open the invoice, and then select File--Print from the menu to print it out, and then return back to print
0
3256
by: KohlerTommy | last post by:
In my application I need to give the user the ability to print duplex if the selected printer supports duplex printing. Many of the printer options do not make much sense in my application, and many of the settings in the common printer dialog would have a negative impact on my printing process. To handle this strict printing constraint on...
0
1911
by: Andrew | last post by:
My VB Application opens an Access Report and has an option to generate the report in PDF once the report is closed. This is accomplished by: - Switching over to the Acrobat Printer ( i.e. PDFWriter ) from the default printer. - Setting a string type sub key ( PDFFilename ) in the registry HKEY_CURRENT_USER\Software\Adobe\Acrobat PDFWriter )...
16
660
by: John Baker | last post by:
HI; I feel like a fool..I put CUTE FTP in my last request for help --it should have been CUTE PDF! I have FTP on my mind because I have been working on a web based application, and somehow my brain got stuck on it..sorry! Hi: I need some help writing code that will "print" a report using Cute PDF.
0
1118
by: Anthony Nystrom | last post by:
I am having trouble with changing printer settings before I raise either the pagesetup dialog or the print preview dialog... Changing the printer name is easy, but I am also trying to change the paper size.... This particular paper size is 30386 Video Top is specific to the printer driver itself... Any sample code as to how to both change the...
0
1636
by: ShaneO | last post by:
There have been similar questions raised in the past, however no answers seem to have been provided, so I thought I'd give it a go. Scenario 1: My Windows Forms app generates (say) 10 pages in a Print Preview Control. These pages are made up of varying sized graphics and text, therefore each page is unique but does rely on the content of...
0
1940
by: neeraj | last post by:
Hi all I have developed on desktop application in Visual Basic for Hotel Management and my client requires multiple printing options here I have multiple printers first default printer which directly connected with source PC other one is in network. The situation is when user give the print command he must be select one respective...
2
9942
by: Brad Pears | last post by:
I have a vb.net 2005 application and am using the print preview screen. This screen has a printer icon on it that the user can use to print the document currently being viewed. It uses the default printer settings to print. I wanted the print preview to appear the same for all users (i.e. a default page size of 8.5x14 (legal) and portrait...
3
9596
by: jpas84 | last post by:
When using JavaScript window.print() command to print in IE, is it possible to set the selected printer in the Print window? In some cases I'd like to have the user's default printer selected, and in other cases have a specific printer selected when the Print window is displayed. The default behavior seems to be that the first time the Print...
0
7658
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7877
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7631
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7943
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6238
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5479
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3631
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.