473,416 Members | 1,657 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

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

spider1916
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 27885
sashi
1,754 Expert 1GB
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
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
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.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=55941&lngWId=1

if this does not work email and I will send it over
Jan 5 '07 #4
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.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=55941&lngWId=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
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 SetDefaultprinter Function still The default printer is keep changing as I select another printer in commondialog printer.

Thanks.
Apr 23 '07 #6
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
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
hi,

i send you an email so you can give a solution?
May 31 '16 #9
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
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...
0
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...
0
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....
16
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...
0
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...
0
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...
0
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...
2
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...
3
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
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,...
0
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...

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.