Databas: Access 2000 (Kanske dåligt att klistra in massa kod här...?)Byta skrivare automatiskt vid utskrift till Datareport
Pllattform Windows 2000
Språk VB
Hur gör jag för att kunna byta till annan skrivare än förvald skrivare
i kod när jag skall skriva ut en Datareport utan att använda Dialogboxen eller .show
2000Sv: Byta skrivare automatiskt vid utskrift till Datareport
Du får bortse från min loggning och felhantering.
/S
Public Const HWND_BROADCAST As Long = &HFFFF&
Public Const WM_WININICHANGE As Long = &H1A
Public 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 Declare Function WriteProfileString Lib "kernel32" _
Alias "WriteProfileStringA" _
(ByVal lpszSection As String, _
ByVal lpszKeyName As String, _
ByVal lpszString As String) As Long
Public Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lparam As Any) As Long
Private Sub SetDefaultPrinter(ByVal PrinterName As String, _
ByVal DriverName As String, _
ByVal PrinterPort As String)
On Error GoTo ErrorHandler
LogIt "clsScannerHandler_SetDefaultPrinter - PRE"
Dim DeviceLine As String
'rebuild a valid device line string
DeviceLine = PrinterName & "," & DriverName & "," & PrinterPort
'Store the new printer information in the
'[WINDOWS] section of the WIN.INI file for
'the DEVICE= item
Call WriteProfileString("windows", "Device", DeviceLine)
'Cause all applications to reload the INI file
Call SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, ByVal "windows")
Done:
LogIt "clsScannerHandler_SetDefaultPrinter - POST"
Exit Sub
ErrorHandler:
Dim lngErrNum As Long: Dim strErrDesc As String: Dim strErrSource As String: lngErrNum = Err.Number: strErrDesc = Err.Description: strErrSource = Err.Source
LogIt "clsScannerHandler_SetDefaultPrinter - ERROR: " & strErrDesc, "Log"
If InDesign Then
Stop: Resume
Else
MsgBox "Ett fel uppstod:" & vbNewLine & strErrDesc & vbNewLine & "Källa: " & "clsScannerHandler_SetDefaultPrinter", , ""
End If
GoTo Done
End Sub
Public Sub RestorePrinter()
On Error GoTo ErrorHandler
LogIt "clsScannerHandler_RestorePrinter - PRE"
Dim Buffer As String
Dim DeviceName As String
Dim DriverName As String
Dim PrinterPort As String
Dim r As Long
'Get the printer information for the currently selected
'printer in the list. The information is taken from the
'WIN.INI file.
Buffer = Space(1024)
Call GetProfileString("PrinterPorts", _
mDefaultPrinterName, "", _
Buffer, Len(Buffer))
'Parse the driver name and port name out of the buffer
GetDriverAndPort Buffer, DriverName, PrinterPort
DoEvents
If DriverName <> "" And PrinterPort <> "" Then
SetDefaultPrinter mDefaultPrinterName, DriverName, PrinterPort
End If
DoEvents
Done:
LogIt "clsScannerHandler_RestorePrinter - POST"
Exit Sub
ErrorHandler:
Dim lngErrNum As Long: Dim strErrDesc As String: Dim strErrSource As String: lngErrNum = Err.Number: strErrDesc = Err.Description: strErrSource = Err.Source
LogIt "clsScannerHandler_RestorePrinter - ERROR: " & strErrDesc, "Log"
If InDesign Then
Stop: Resume
Else
MsgBox "Ett fel uppstod:" & vbNewLine & strErrDesc & vbNewLine & "Källa: " & "clsScannerHandler_RestorePrinter", , ""
End If
GoTo Done
End Sub