| | |
Select Printer From List
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Let you choose between all printers available on your pc or network. Download zip and enjoy. Royal free.
Option Explicit Private Declare Function GetProfileString Lib "kernel32.dll" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long Private Function GetDefaultPrinter() As String Dim strBuffer As String * 254 Dim iRetValue As Long Dim strDefaultPrinterInfo As String Dim tblDefaultPrinterInfo() As String ' Retreive current default printer information iRetValue = GetProfileString("windows", "device", ",,,", strBuffer, 254) strDefaultPrinterInfo = Left(strBuffer, InStr(strBuffer, Chr(0)) - 1) tblDefaultPrinterInfo = Split(strDefaultPrinterInfo, ",") GetDefaultPrinter = tblDefaultPrinterInfo(0) End Function Private Sub AddToPrinterList(LBox As ListView, ByRef Counter As Integer, Col1 As String, DefaultPrinter As Boolean) 'add the printers to the list view control 'add one to the printer number for the index since the control does not like zero and then 'remove again when you want to assign the printer With LBox .ListItems.Add Counter + 1, Col1 & Counter, Col1, 2 If DefaultPrinter Then .ListItems(Counter + 1).Selected = True End If End With End Sub Private Sub cmdCancel_Click() Unload Me End Sub Private Sub cmdPrint_Click() 'set the printer and print something If Len(PrinterList.SelectedItem.Text) > 0 Then Set Printer = Printers(PrinterList.SelectedItem.Index - 1) Printer.Copies = NoCopies End If 'add any print statements here that you want Printer.Print "hello" Printer.EndDoc cmdCancel_Click End Sub Private Sub Form_Load() Dim Counter As Integer Dim defPrinter As String 'enumerate the printers collection If Printers.Count > 0 Then defPrinter = GetDefaultPrinter For Counter = 0 To Printers.Count - 1 AddToPrinterList PrinterList, Counter, Printers(Counter).DeviceName, Printers(Counter).DeviceName = defPrinter Next Else MsgBox "No Printers Are Installed!" & vbCrLf & vbCrLf & _ "You must install at least one printer before you can print!", vbCritical, "No Printer Available!" Unload Me End If End Sub Private Sub VScroll1_Change() 'use a scroll bar to increment the number of copies 'can add loads of other printing options as you see fit NoCopies = Abs(VScroll1) End Sub
Similar Threads
- How To Print Directly to Printer (PHP)
- populate select list from multiple Mysql tables (PHP)
- New Vista notebook Access Denied by XP network printer (can see it though) (Windows Vista and Windows 7)
- Printer install and Mac / Linux USB pen (IT Professionals' Lounge)
- <select> options selection on mouse over (JavaScript / DHTML / AJAX)
- Can't connect to printer on network (OS X)
- HTML Select and PHP 5 - Issue (PHP)
- Error Creating Folder message during installation (OS X)
- "Error in linking List box with the VB6.0 database" (Visual Basic 4 / 5 / 6)
- OSX G4 wont talk to my Epson CX3200 Printer (Apple Hardware)
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner birth bmp c++ calculator cd cells.find click client code college column component connection copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows



