Tony,
This is not a solution but a suggestion. Let the user choose to which
printer each printing should go to from a dialog. Create two listboxes in
the dialog, one for the documents and on for the labels, and populate them
with the printer names. Store the printer names the user selected in the
registry and use them as default later on. Don't forget to give the user the
option to change it later.
In your code you can have the following logic:
*Get the printer names from the registry (se Get/SaveSetting functions)
*Save the 'ActivePrinter'
*Set the ActivePrinter for the document
*Print the document
*Set the AtivePrinter for the labels
*Print the labels
*Restore the ActivePrinter setting
To get the names of the printers you can use the following code:
'-----------------------------
Private Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyA" _
(ByVal pTraget As String, ByVal pSource As Long) As Long
Private Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" _
(ByVal pString As Long) As Long
Private Declare Function EnumPrinters Lib "winspool.drv" _
Alias "EnumPrintersA" (ByVal nFlags As Long, _
ByVal pName As String, ByVal nLevel As Long, _
pPrinterEnum As Long, ByVal nBufLen As Long, _
pNeeded As Long, pPrtReturned As Long) As Long
Const PRINTER_ENUM_LOCAL = &H2
Const PRINTER_ENUM_NETWORK = &H40
Option Explicit
'-----------------------------
Function GetPrinters() As Collection
Dim aLngBuff() As Long
Dim nBytes As Long
Dim nNeeded As Long
Dim nNumPrinters As Long
Dim i As Long
Dim sPrtName As String
Dim nRetval As Long
Dim nElement As Long
Dim cRetVal As Collection
' Initialize variables
Set cRetVal = New Collection
Set GetPrinters = cRetVal
nBytes = 0
ReDim aLngBuff(0) As Long
' Get the required buffer size
nRetval = EnumPrinters(PRINTER_ENUM_LOCAL, "", _
1, aLngBuff(0), nBytes, nNeeded, nNumPrinters)
If nRetval = 0 Or nNeeded = 0 Then
' An error occured during the call
' or no printers found
Exit Function
End If
nBytes = nNeeded
' Resize the Long Array buffer
ReDim aLngBuff(Int(nBytes / 4) + 1) As Long
' Get the printers
nRetval = EnumPrinters(PRINTER_ENUM_LOCAL, "", _
1, aLngBuff(0), nBytes, nNeeded, nNumPrinters)
If nRetval = 0 Then
' An error occured during the call
Exit Function
End If
For i = 0 To nNumPrinters - 1
nElement = 4 * i + 2 ' Calculate the array element
' Get the size of the string and size the variable
sPrtName = Space(lstrlen(aLngBuff(nElement)))
' Copy the string from the API call to our variable
nRetval = lstrcpy(sPrtName, aLngBuff(nElement))
' Add the string to the collection
cRetVal.Add sPrtName
Next
End Function
'-----------------------------
Regards,
Lars-Eric