Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Printers in vb

Posted on 2002-06-22
6
Medium Priority
?
241 Views
Last Modified: 2010-08-05
Hi ,
 i have two Printers defined on my PC one of them is set to default ... now please how can i change the printer in my program and prints on the not default printer ...


thanx alot
Loay
0
Comment
Question by:loay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Expert Comment

by:sumantachandra
ID: 7101522

You have two choise. Either u can have code option or u can include CommonDialog control in to ur project.

if u want to print directlly from your project with out knowing the user then

Change the current printer





or go to project menu -> then components -> include CommonDialog Control

Create a Command Button say as "Printer Setting" and attached the following code.

CommonDialog1.Showprinter

then the printer list setting would be appear from where user can select printer and all the assoi\ciated setting.




0
 

Author Comment

by:loay
ID: 7101532
am sorry this is not what i want ,, i want it by coding how to change the printer by code ...
thanx alot and sorry
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 120 total points
ID: 7101672
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Expert Comment

by:PNJ
ID: 7103300
Here's the code that handles about 50 different printers around our company. I have stripped out the FAX bit and some extraneous stuff that checks our Oracle database - so there's some extra "Dim's" that you should remove.

It checks the printers in the printers folder and sets the printer object to the one required:

   If Not SetPrinter ("DEVELOPERS") Then
      "Printer isn't there"
   Else
      Printer.Font.Size = 20
      Printer.Print "This will print on DEVELOPERS"
      Printer.EndDoc
   Endif


Function SetPrinter(WantPrinter as string) As Boolean
   
   Dim objPrinter As Printer, bQueueExists As Boolean
   Dim sFaxNumber As String, sFaxName As String
   Dim sSendTime As String, sSendDate As String, sCompany As String
   Dim sSubject As String, sKeyword As String, sBillingCode As String
   Dim sMode As String, sRecipient As String
   Dim sAction As String, SaveErr As Long
   Dim PaperBin As Integer
   Dim PrinterName As String, Pos As Integer
   Dim Copies As Integer
   Dim RS As ADODB.Recordset, SQL As String
   
   On Error GoTo SetPrinter_Error
   
   SetPrinter = False
   
   sAction = "Printer"
   bQueueExists = False

   For Each objPrinter In Printers
     
         ' NT can have printers of the name "\\Server\PrinterName". Need to strip off
         ' the printer name
         PrinterName = UCase$(objPrinter.DeviceName)

         Pos = InStr(PrinterName, "\" & WantPrinter)
         If Pos > 0 Then PrinterName = Trim$(Mid$(PrinterName, Pos + 1))

         If PrinterName = WantPrinter Then

            sAction = "set prt"

            ' Don't set it if already set
            If Printer.DeviceName <> objPrinter.DeviceName Then

               Set Printer = objPrinter <= This is the important bit

            End If
            bQueueExists = True
            Exit For
         End If

      Next objPrinter

      If Not bQueueExists Then
         sAction = "raise"
         Err.Raise 9999, , "Queue " & _
            WantPrinter & " does not exist on PC"
         Set objPrinter = Nothing
         Exit Function
      End If
     
      Set objPrinter = Nothing
   
   SetPrinter = True
   
   Exit Function

SetPrinter_Error:
   <some error handler as required>
End Function

0
 

Author Comment

by:loay
ID: 7126250
SORRY SIR BUT IT DIDNT BUT THANX FOR TRYING HELPING ME I AM SORRY AGIAN AND THANX ....
p.s : emoreau ANSWER OR THE URL HE GAVE ME IS VERY GOOD ONE
0
 

Author Comment

by:loay
ID: 7126255
THANX ALOT
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question