Detecting Default Printer --> Resolved - Thank you :)
I have this code in which I read all the printers on the PC, it works just fine..
VB Code:
For Each OBJ In Printers
Call frmSelPrinter.cboPrinters.AddItem(OBJ.DeviceName)
Next
My question is once I have done this and I have all the printers loaded into my combo box I want to set the index to the one that is the default printer. However I do not know how to detect which one is the default printer.. Can some one please help meout with this?
Thank you :D
Rudy
Re: Detecting Default Printer --> Resolved - Thank you :)
Quote:
Originally Posted by
RhinoBull
There is a little more accurate method to determine default printer:
VB Code:
Option Explicit
Private Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" _
(ByVal lpAppName As String, ByVal lpKeyName As String, _
ByVal lpDefault As String, ByVal lpReturnedString As String, _
ByVal nSize As Long) As Long
Public Function GetDefaultPrinter() As String
'=============================================
Dim bfr$, ret&, Pos&
bfr = String$(128, 0)
ret = GetProfileString("WINDOWS", "DEVICE", "", bfr, 127)
bfr = Left(bfr, ret)
Pos = InStr(1, bfr, ",")
GetDefaultPrinter = Left(bfr, Pos - 1)
End Function
'usage:
Private Sub Command1_Click()
'============================
Dim prtName As String
prtName = GetDefaultPrinter
Label1.Caption = "Default Printer: " & prtName
End Sub
i dont understand, but is the printer.deviceName not suppose to give this
Re: Detecting Default Printer --> Resolved - Thank you :)
Quote:
Originally Posted by
coolcurrent4u
i dont understand, but is the printer.deviceName not suppose to give this
Not really. Try this:
Code:
Private Sub Command1_Click()
Dim prt As Printer
For Each prt In Printers
Debug.Print prt.DeviceName
Next prt
End Sub
After running that simple snippet you will get list of all printers currently available on your system.
But DeviceName cannot tell you which one is your default.
Re: Detecting Default Printer --> Resolved - Thank you :)
Quote:
Originally Posted by
RhinoBull
Not really. Try this:
Code:
Private Sub Command1_Click()
Dim prt As Printer
For Each prt In Printers
Debug.Print prt.DeviceName
Next prt
End Sub
After running that simple snippet you will get list of all printers currently available on your system.
But DeviceName cannot tell you which one is your default.
you dont have to loop, just call printer.devicename and it will give you the default. i have tried this many times
Re: Detecting Default Printer --> Resolved - Thank you :)
Quote:
you dont have to loop, just call printer.devicename and it will give you the default. i have tried this many times
if the current printer for your application is not the default printer, then it will not return the default printer, but the printer your program is using