PC Review


Reply
Thread Tools Rate Thread

How to check the existing of a printer?

 
 
=?Utf-8?B?Y2xhcmE=?=
Guest
Posts: n/a
 
      20th Jul 2007
Hi

How to check the existing of a printer?

Clara
--
thank you so much for your help
 
Reply With Quote
 
 
 
 
=?Utf-8?B?QW5vbnk=?=
Guest
Posts: n/a
 
      20th Jul 2007
To check the existence of a printer and display the name of the existing
printer, copy this code into a normal VBA module and run it:


Private Declare Function GetProfileStringA Lib "kernel32" _
(ByVal lpApplName As String, ByVal lpKeyName As String, _
ByVal lpDefault As String, ByVal lpReturnedString As _
String, ByVal nSize As Long) As Long

Sub Printer()
Dim strLPT As String * 255
Dim Result As String
Dim Resultlength, Comma1, Comma2
Dim Printer As String, Driver As String, Port As String
Dim Msg As String

Call GetProfileStringA("Windows", "Device", "", strLPT, 254)

On Error Resume Next
Result = Application.Trim(strLPT)
Resultlength = Len(Result)
If Err <> 0 Then
MsgBox "No printer detected.", vbInformation, "Printer"
Exit Sub
End If
On Error GoTo 0

Comma1 = InStr(1, Result, ",", 1)
Comma2 = InStr(Comma1 + 1, Result, ",", 1)

Printer = Left(Result, Comma1 - 1)
If Printer = "" Then
MsgBox "No printer detected.", vbInformation, "Printer"
Exit Sub
End If

Msg = "Printer: " & Printer & vbCrLf
MsgBox Msg, , "Existing Printer"

End Sub
 
Reply With Quote
 
=?Utf-8?B?Y2xhcmE=?=
Guest
Posts: n/a
 
      27th Jul 2007
HI Anony,

Thank you for your code. It can detect a printer's profile. What I really
want to need as follow:

before printing, I want to check whether the printer is in normal work
mode, such as network cable is connected, there is paper ect.

Is it possible to do it?

Thank you very much

Clara
--
thank you so much for your help


"Anony" wrote:

> To check the existence of a printer and display the name of the existing
> printer, copy this code into a normal VBA module and run it:
>
>
> Private Declare Function GetProfileStringA Lib "kernel32" _
> (ByVal lpApplName As String, ByVal lpKeyName As String, _
> ByVal lpDefault As String, ByVal lpReturnedString As _
> String, ByVal nSize As Long) As Long
>
> Sub Printer()
> Dim strLPT As String * 255
> Dim Result As String
> Dim Resultlength, Comma1, Comma2
> Dim Printer As String, Driver As String, Port As String
> Dim Msg As String
>
> Call GetProfileStringA("Windows", "Device", "", strLPT, 254)
>
> On Error Resume Next
> Result = Application.Trim(strLPT)
> Resultlength = Len(Result)
> If Err <> 0 Then
> MsgBox "No printer detected.", vbInformation, "Printer"
> Exit Sub
> End If
> On Error GoTo 0
>
> Comma1 = InStr(1, Result, ",", 1)
> Comma2 = InStr(Comma1 + 1, Result, ",", 1)
>
> Printer = Left(Result, Comma1 - 1)
> If Printer = "" Then
> MsgBox "No printer detected.", vbInformation, "Printer"
> Exit Sub
> End If
>
> Msg = "Printer: " & Printer & vbCrLf
> MsgBox Msg, , "Existing Printer"
>
> End Sub

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check DataGridView for existing row Jon Microsoft C# .NET 6 4th Dec 2009 09:10 AM
Check For Existing Record ridgerunner Microsoft Access Forms 29 23rd May 2008 03:54 PM
Check for Existing Else go to New tbrogdon@gmail.com Microsoft Access Form Coding 36 14th Feb 2008 05:07 PM
Check for existing contact Edwin van Hulst Microsoft Outlook Form Programming 0 21st Nov 2005 06:38 PM
Re: Check for existing table (using VBA) Tim Ferguson Microsoft Access VBA Modules 0 22nd Jul 2004 06:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:24 AM.