ESCOLHER IMPRESSORA

RICARDOCGD 15/04/2016 01:20:21
#460943
Como eu posso escolher a impressora num form que possui um relatorio em crystal report?
FABRICIOWEB 15/04/2016 07:31:42
#460945
Private Sub Form_Load()
Dim r As Long
Dim Buffer As String

[ô] Get the list of available printers from WIN.INI
Buffer = Space(8192)
r = GetProfileString([Ô]PrinterPorts[Ô], vbNullString, [Ô][Ô], _
Buffer, Len(Buffer))

[ô] Display the list of printer in the ListBox List1
ParseList combo_impressoras, Buffer

[ô]informa a impressora atual selecionada
atual.Caption = Printer.DeviceName
End Sub
Private Sub combo_impressoras_GotFocus()
combo_impressoras.SelStart = 0
combo_impressoras.BackColor = &HFFFF&
End Sub
Private Sub combo_impressoras_KeyDown(KeyCode As Integer, Shift As Integer)
If PosicaoDoCombo = 0 Then If KeyCode = 40 Then SendKeys [Ô]{F4}[Ô]: PosicaoDoCombo = 1
End Sub
Private Sub combo_impressoras_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub
Private Sub combo_impressoras_LostFocus()
combo_impressoras.BackColor = &H80000005
End Sub
Private Sub Command1_Click()
If combo_impressoras.Text = Empty Then
MsgBox [Ô]Selecione uma opção de impressora na lista ...[Ô], vbExclamation
combo_impressoras.SetFocus
Else
DoEvents
Me.MousePointer = 11


DoEvents
Dim osinfo As OSVERSIONINFO
Dim retvalue As Integer

osinfo.dwOSVersionInfoSize = 148
osinfo.szCSDVersion = Space$(128)
retvalue = GetVersionExA(osinfo)

Call WinNTSetDefaultPrinter

atual.Caption = Printer.DeviceName
atual.BackColor = &HFFFF&
info01.Caption = [Ô]Nova impressora :[Ô]
info01.BackColor = &HFFFF&

DoEvents
Me.MousePointer = 0
End If
End Sub
[ô]definição da impressora do sistema
Private Sub SetDefaultPrinter(ByVal PrinterName As String, _
ByVal DriverName As String, ByVal PrinterPort As String)
Dim DeviceLine As String
Dim r As Long
Dim l As Long
DeviceLine = PrinterName & [Ô],[Ô] & DriverName & [Ô],[Ô] & PrinterPort
[ô] Store the new printer information in the [WINDOWS] section of
[ô] the WIN.INI file for the DEVICE= item
r = WriteProfileString([Ô]windows[Ô], [Ô]Device[Ô], DeviceLine)
[ô] Cause all applications to reload the INI file:
l = SendMessage(HWND_BROADCAST, WM_WININICHANGE1, 0, [Ô]windows[Ô])

End Sub
Private Sub GetDriverAndPort(ByVal Buffer As String, DriverName As _
String, PrinterPort As String)

Dim iDriver As Integer
Dim iPort As Integer
DriverName = [Ô][Ô]
PrinterPort = [Ô][Ô]

[ô] The driver name is first in the string terminated by a comma
iDriver = InStr(Buffer, [Ô],[Ô])
If iDriver > 0 Then

[ô] Strip out the driver name
DriverName = Left(Buffer, iDriver - 1)

[ô] The port name is the second entry after the driver name
[ô] separated by commas.
iPort = InStr(iDriver + 1, Buffer, [Ô],[Ô])

If iPort > 0 Then
[ô] Strip out the port name
PrinterPort = Mid(Buffer, iDriver + 1, _
iPort - iDriver - 1)
End If
End If
End Sub
Private Sub ParseList(lstCtl As Control, ByVal Buffer As String)
Dim i As Integer
Dim S As String

Do
i = InStr(Buffer, Chr(0))
If i > 0 Then
S = Left(Buffer, i - 1)
If Len(Trim(S)) Then lstCtl.AddItem S
Buffer = Mid(Buffer, i + 1)
Else
If Len(Trim(Buffer)) Then lstCtl.AddItem Buffer
Buffer = [Ô][Ô]
End If
Loop While i > 0
End Sub
[ô]se for para selecionar impressoras no sistema operacional XP
Private Sub WinNTSetDefaultPrinter()
Dim Buffer As String
Dim DeviceName As String
Dim DriverName As String
Dim PrinterPort As String
Dim PrinterName As String
Dim r As Long
If combo_impressoras <> Empty Then
[ô] Get the printer information for the currently selected
[ô] printer in the list. The information is taken from the
[ô] WIN.INI file.
Buffer = Space(1024)
PrinterName = combo_impressoras.Text
r = GetProfileString([Ô]PrinterPorts[Ô], PrinterName, [Ô][Ô], _
Buffer, Len(Buffer))

[ô] Parse the driver name and port name out of the buffer
GetDriverAndPort Buffer, DriverName, PrinterPort

If DriverName <> [Ô][Ô] And PrinterPort <> [Ô][Ô] Then
SetDefaultPrinter combo_impressoras.Text, DriverName, PrinterPort
If Printer.DeviceName <> combo_impressoras.Text Then
[ô] Make sure Printer object is set to the new printer
SelectPrinter (combo_impressoras.Text)
End If
End If
End If
End Sub

RICARDOCGD 16/04/2016 03:58:10
#461022
Seria possivel assim

Tópico encerrado , respostas não são mais permitidas