Maybe you should try using API, ie. the DEVMODE structure and
DocumentProperties, DeviceCapabilities etc
Some years ago I had a written quite a few lines of code about printing.
For starters, here's a sub that returns all papersizes and their
corresponding long id of a printer:
Private Declare Function DeviceCapabilities Lib "winspool.drv" _
Alias "DeviceCapabilitiesA" (ByVal lpDeviceName As String, _
ByVal lpPort As String, ByVal iIndex As Long, ByVal lpOutput As String,
_
ByVal lpDevMode As Long) As Long
Private Declare Function DeviceCapabilities2 Lib "winspool.drv" _
Alias "DeviceCapabilitiesA" (ByVal lpDeviceName As String, _
ByVal lpPort As String, ByVal iIndex As Long, ptOutput As Any, _
ByVal lpDevMode As Long) As Long
Private Const DC_FIELDS = 1
Private Const DC_PAPERS = 2
Private Const DC_PAPERSIZE = 3
Private Const DC_MINEXTENT = 4
Private Const DC_MAXEXTENT = 5
Private Const DC_BINS = 6
Private Const DC_DUPLEX = 7
Private Const DC_SIZE = 8
Private Const DC_EXTRA = 9
Private Const DC_VERSION = 10
Private Const DC_DRIVER = 11
Private Const DC_BINNAMES = 12
Private Const DC_ENUMRESOLUTIONS = 13
Private Const DC_FILEDEPENDENCIES = 14
Private Const DC_TRUETYPE = 15
Private Const DC_PAPERNAMES = 16
Private Const DC_ORIENTATION = 17
Private Const DC_COPIES = 18
Private Const DCTT_BITMYD = &H1&
Private Const DCTT_DOWNLOAD = &H2&
Private Const DCTT_SUBDEV = &H4&
Private Declare Function OpenPrinter Lib "winspool.drv" Alias _
"OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _
ByVal pDefault As Long) As Long
Private Declare Function DocumentProperties Lib "winspool.drv" _
Alias "DocumentPropertiesA" (ByVal hwnd As Long, _
ByVal hPrinter As Long, ByVal pDeviceName As String, _
pDevModeOutput As Any, pDevModeInput As Any, ByVal fMode As Long) _
As Long
Private Declare Function ClosePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" _
(ByVal lpDriverName As String, ByVal lpDeviceName As String, _
ByVal lpOutput As Long, ByVal lpInitData As Long) As Long
Public Function GetPrinterPaperSizes(ByRef gPaperSize() As Long, _
ByRef sPaperSize() As String, _
ByRef gPaperSizeCounter As Long) As Long
On Error GoTo Er
Dim PaperCount As Long
Dim PaperName As String
Dim sA As String
Dim tName As String
Dim iA As Long
Dim dl As Long
Dim gArray() As Integer
'initialise with failure
GetPrinterPaperSizes = 0
'is there a printer set?
If mhDCPrinter = 0 Then Exit Function
'find out how many paper names there are
PaperCount = DeviceCapabilities(mPrinterDeviceName, _
mPrinterPort, DC_PAPERNAMES, vbNullString, 0&)
'error
If PaperCount <= 0 Then Exit Function
'now dimension the string large enough to hold them all
PaperName = String$(64 * PaperCount, 0)
'get 'em
dl = DeviceCapabilities(mPrinterDeviceName, mPrinterPort, _
DC_PAPERNAMES, PaperName, 0)
If dl = -1 Then Exit Function
'ok
ReDim sPaperSize(1 To PaperCount) As String
'load the results
For iA = 1 To PaperCount
tName = Mid$(PaperName, (iA - 1) * 64 + 1)
sPaperSize(iA) = StripNulls(tName)
Next iA
'find out how many paper names there are, using the default DevMode
dl = 0
dl = DeviceCapabilities(mPrinterDeviceName, _
mPrinterPort, DC_PAPERS, vbNullString, 0&)
If dl <= 0 Or dl <> PaperCount Then Exit Function
ReDim gArray(1 To dl) As Integer
dl = DeviceCapabilities2(mPrinterDeviceName, _
mPrinterPort, DC_PAPERS, gArray(1), 0&)
If dl <= 0 Then Exit Function
ReDim gPaperSize(1 To PaperCount) As Long
For iA = 1 To PaperCount
gPaperSize(iA) = gArray(iA)
Next iA
gPaperSizeCounter = PaperCount
GetPrinterPaperSizes = 1
Er:
End Function
Also...
Private Function CreatePrinterDC(sPrinterName As String) As Long
On Error GoTo Er
Dim X As Printer
Dim dl As Long
CreatePrinterDC = 0
If mhDCPrinter <> 0 Then dl = DeleteDC(mhDCPrinter)
For Each X In Printers
If X.DeviceName = sPrinterName Then
mhDCPrinter = CreateDC(X.DriverName, X.DeviceName, 0&, 0&)
If mhDCPrinter <> 0 Then
'success
CreatePrinterDC = 1
'store these values
mPrinterDeviceName = X.DeviceName
mPrinterDriverName = X.DriverName
mPrinterPort = X.Port
'get DEVMODE
GetDEVMODE '<<< ignore this
'load data
LoadPrinterData '<<< ignore this
End If
Exit Function
End If
Next X
Er:
End Function
And...
Private Function StripNulls(OriginalStr As String) As String
On Error Resume Next
If (InStr(OriginalStr, Chr$(0)) > 0) Then
OriginalStr = Left(OriginalStr, InStr(OriginalStr, Chr$(0)) - 1)
End If
StripNulls = Trim$(OriginalStr)
End Function
This should get you started - it's been a long time since I left these
projects, anyway!
Cheers
A.
"Chris Ott" <ch***@dalb.com> wrote in message
news:2P***********@news01.roc.ny...
I am importing data from a flat file, performing many calculations then
printing the information directly to a network printer. I am using Visual
Basic ver 6 for this.
Thanks