• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 365
  • Last Modified:

Add printer path to a text box

Hello all,

I need to fix this code about setting.

I need to be able to select and save a printer by default.

For that, i want to save the printer path to the text3.

How can i do this please?

Thanks again.


CommonDialog1.FileName = App.Path
CommonDialog1.ShowPrinter
Text3.Text = CommonDialog1.Printer

Open in new window

0
Wilder1626
Asked:
Wilder1626
  • 6
  • 3
1 Solution
 
game-masterCommented:

good morning!

have u try something like this...


CommonDialog1.PrinterDefault = True


this will set the default printer..


game-master
0
 
Wilder1626Author Commented:
It's because i have 3 printers. I need to be able to change it from time to time.
0
 
deicidedxCommented:
You dont have to set the reference to a path ...your printer is an object so you can show in the textbox its name after the user selects it.


Dim oPrinter As Printer
Dim OldPrinter As Printer.

'To scan for all printers
For Each oPrinter In Printers
       Debug.Print oPrinter.DeviceName
Next oPrinter

'To set a printer as used by the program
Set OldPrinter = Printer
Set Printer = oPrinter
'Do your print routine.
'Set the printer back
Set Printer = OldPrinter
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Wilder1626Author Commented:
I will try it.

I'll be back with the result.

Thanks
0
 
Wilder1626Author Commented:
Good,

I will use this one. It work perfectly like this.

Thanks again for your help.
0
 
Wilder1626Author Commented:
I forgot to put the code.
Private Sub cboPrinters_Click()
   
   Dim i As Integer
   Dim p As Printer
   For Each p In Printers
       If i = cboPrinters.ListIndex Then
           Set Printer = p
           Exit For
       End If
       i = i + 1
   Next p
   Label1.Caption = Printer.DeviceName
   
End Sub

Private Sub Form_Load()

   PopulatePrinters

End Sub
Private Sub PopulatePrinters()
   Dim p As Printer
   Dim i As Integer
   i = 0

   For Each p In Printers
       cboPrinters.AddItem p.DeviceName
       If p.DeviceName = Printer.DeviceName Then
           cboPrinters.ListIndex = i
       End If
       i = i + 1
   Next p
End Sub

Open in new window

0
 
deicidedxCommented:
I see from your comment that you were not satisfied with my answer. I didnt thought you would need the whole code. I think i anwered your question and gave you a solution which lead you to the final one.
Its not fair to close it like that but if its your decision the fine ...
Thanks anyway
0
 
Wilder1626Author Commented:
Sorry, i did give you points for this.

Let me try again.
0
 
Wilder1626Author Commented:
Sorry, for this. I dont no why the points didnt transfert to you.

Sorry again.
0
 
deicidedxCommented:
No problem man. The question was in closing mode ...maybe you did that by mistake.
Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now