Seleccionar Impresora
y las caracter�sticas de c�mo imprimir
Fecha: 03/Feb/99 (21/Sep/98)
Autor: Norman A. Armas [email protected]
Esta forma yo la uso para seleccionar el printer y las caracteristicas de como quiero imprimir los reportes en Crystal Report 6.0 (usando Report Engine)
El codigo yo lo uso con Crystal Report pero es general para poder seleccionar uno el printer y las caracteristicas de como quieres imprimir. Esta idea se me ocurrio ya que si uno usa un generador de reportes, cualquiera que sea se ve uno amarrado a las posibilidades que le da este, de esta otra manera uno basandose en la coleccion de printers de windows puede hacerlo a su gusto y en base a la seleccion que el usuario haga pasarle estos parametros a el generador que uno tenga siempre que este le de las posibilidades a uno para ello.
Saludos
Norman
[email protected]
El c�digo de ejemplo:
'
'Este codigo es en el Standard Modulo
Public Type SetPrinters
Driver As String
Name As String
Port As String
Copies As Integer
RangePages As Boolean
StartPage As Integer
StopPage As Integer
Collation As Boolean
End Type
Public PrinterSelect As SetPrinters
'Este codigo es en la forma para seleccionar el printer
'***********************************************************************
'Program : Printers - frmHRPrinters
'Author : Norman Armas
'Date : 03/17/98
'***********************************************************************
Option Explicit
Dim PrinterAvailable As Printer
Dim lItem As Integer
Dim n As Integer
Dim PrinterDefault As String
Private Sub cboPrinters_Click()
lItem = cboPrinters.ListIndex
End Sub
Private Sub cmdCancel_Click()
gPrinterCancel = True
Unload frmHRPrinters
End Sub
Private Sub cmdOK_Click()
With PrinterSelect
.Driver = Printers(lItem).DriverName
.Name = Printers(lItem).DeviceName
.Port = Printers(lItem).Port
.Copies = Val(txtCopies)
If optRangePages Then
.RangePages = True
.StartPage = Val(txtFrom)
.StopPage = Val(txtTo)
End If
.Collation = IIf(chkCollate, True, False)
End With
Unload frmHRPrinters
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
OnOffInsert Screen.ActiveControl, KeyCode
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
KeyAscii = CharUCase(KeyAscii, DisableUcase)
If KeyAscii = 13 Then
SendEnter
KeyAscii = 0
End If
End Sub
Private Sub Form_Load()
'$Guille: Este procedimiento para centrar los forms no se incluye en el c�digo
'CenterForm Me, False
Screen.MousePointer = vbDefault
PrinterDefault = ""
lItem = -1
SQL = "select * from printers where reportid='" & Trim(gKeyValue) & "'"
Set rs = rsOpen(SQL, False)
'MsgBox rs.RowCount
If rs.RowCount > 0 Then
PrinterDefault = Trim(rs!printerid)
End If
For Each PrinterAvailable In Printers
cboPrinters.AddItem PrinterAvailable.DeviceName
cboPrinters.ItemData(cboPrinters.NewIndex) = n
If Trim(PrinterDefault) <> "" Then
If Trim(PrinterAvailable.DeviceName) = Trim(PrinterDefault) Then
lItem = n
End If
Else
If Trim(PrinterAvailable.DeviceName) = Trim(Printer.DeviceName) Then
lItem = n
End If
End If
n = n + 1
Next
If lItem = -1 Then
MsgBox "Default Printer not Install on Workstation", vbExclamation
lItem = 0
End If
cboPrinters.ListIndex = lItem
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set frmHRPrinters = Nothing
End Sub
Private Sub optRangeAll_Click()
txtFrom.Enabled = IIf(optRangeAll, False, True)
txtTo.Enabled = IIf(optRangeAll, False, True)
End Sub
Private Sub optRangePages_Click()
txtFrom.Enabled = IIf(optRangeAll, False, True)
txtTo.Enabled = IIf(optRangeAll, False, True)
End Sub
Private Sub txtCopies_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If
End Sub
Private Sub txtFrom_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If
End Sub
Private Sub txtTo_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If
End Sub
End Function