?
Solved

Add printer path to a text box

Posted on 2009-12-21
10
Medium Priority
?
362 Views
Last Modified: 2012-05-08
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
Comment
Question by:Wilder1626
  • 6
  • 3
10 Comments
 
LVL 13

Expert Comment

by:game-master
ID: 26101652

good morning!

have u try something like this...


CommonDialog1.PrinterDefault = True


this will set the default printer..


game-master
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 26104139
It's because i have 3 printers. I need to be able to change it from time to time.
0
 
LVL 4

Accepted Solution

by:
deicidedx earned 2000 total points
ID: 26130064
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 11

Author Comment

by:Wilder1626
ID: 26131021
I will try it.

I'll be back with the result.

Thanks
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 26137944
Good,

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

Thanks again for your help.
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 26137948
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
 
LVL 4

Expert Comment

by:deicidedx
ID: 26138028
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
 
LVL 11

Author Comment

by:Wilder1626
ID: 26138061
Sorry, i did give you points for this.

Let me try again.
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 31668769
Sorry, for this. I dont no why the points didnt transfert to you.

Sorry again.
0
 
LVL 4

Expert Comment

by:deicidedx
ID: 26138237
No problem man. The question was in closing mode ...maybe you did that by mistake.
Thank you
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

850 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