Hello,

I have inherited an application written in VB6 that does not handle the number of print copies properly. Changing the number of copies to a number other than one(1) results in only (1) print.

I am new at VB6, and would appreciate any tips on how to address this situation.

thank you.

please pass more information .

The code appears below, and I understand that txtCopies section is the culprit.

'/* ------------------------------------------------------------------------- *\
'   m_UPDATEPRINTER()
'
'   Retrieves printer information for the selected printer.
'
'\* ------------------------------------------------------------------------- */

Private Sub m_UpdatePrinter()

On Error GoTo errHandler

    Dim mhPrinter       As Long
    Dim lRet            As Long
    Dim pDef            As PRINTER_DEFAULTS
    Dim SizeNeeded      As Long
    Dim buffer()        As Long
    Dim Index           As Long
    Dim lpDevMode       As Long

    lRet = OpenPrinter(Printer.DeviceName, mhPrinter, pDef)
    
    Index = 2
    
    ReDim Preserve buffer(0 To 1) As Long
    lRet = GetPrinterApi(mhPrinter, Index, buffer(0), UBound(buffer), SizeNeeded)
    ReDim Preserve buffer(0 To (SizeNeeded / 4) + 3) As Long
    lRet = GetPrinterApi(mhPrinter, Index, buffer(0), UBound(buffer) * 4, SizeNeeded)
    lRet = ClosePrinter(mhPrinter)
    
    With m_PrinterInfo '\\ This variable is of type PRINTER_INFO_2
       .pServerName = StringFromPointer(buffer(0), 1024)
       .pPrinterName = StringFromPointer(buffer(1), 1024)
       .pShareName = StringFromPointer(buffer(2), 1024)
       .pPortName = StringFromPointer(buffer(3), 1024)
       .pDriverName = StringFromPointer(buffer(4), 1024)
       .pComment = StringFromPointer(buffer(5), 1024)
       .pLocation = StringFromPointer(buffer(6), 1024)
       '.pDevMode = buffer(7)
       lpDevMode = buffer(7)
       .pSepFile = StringFromPointer(buffer(8), 1024)
       .pPrintProcessor = StringFromPointer(buffer(9), 1024)
       .pDatatype = StringFromPointer(buffer(10), 1024)
       .pParameters = StringFromPointer(buffer(11), 1024)
       '.pSecurityDescriptor = buffer(12)
       .Attributes = buffer(13)
       .priority = buffer(14)
       .DefaultPriority = buffer(15)
       .StartTime = buffer(16)
       .UntilTime = buffer(17)
       .Status = buffer(18)
       '.JobsCount = buffer(19)
       .AveragePPM = buffer(20)
       
        CopyMemory .pDevMode, ByVal lpDevMode, Len(.pDevMode)
        Printer.ColorMode = .pDevMode.dmColor
        Printer.Orientation = .pDevMode.dmOrientation
    End With

    txtCopies.Text = Printer.Copies  'This restricts the print to only 1 page!!!
    
    lblStatusValue.caption = m_GetStatusText(m_PrinterInfo.Status)
    lblTypeValue.caption = m_PrinterInfo.pDriverName
    lblWhereValue.caption = m_PrinterInfo.pPortName
    lblCommentValue.caption = m_PrinterInfo.pComment
    
    Exit Sub
errHandler:
    Call ErrorHandler.HandleError(etALARM, Me.Name, "m_UpdatePrinter")
    Resume Next
End Sub

These is copy paste from help in msdn.

For the Printer object, multiple copies may or may not be collated, depending on the printer driver. Multiple copies of the entire document or multiple copies of each page may be printed. For printers that don't support collating, set Copies = 1, and then use a loop in code to print multiple copies of the entire document.

Note The effect of the properties of the Printer object depends on the driver supplied by the printer manufacturer. Some property settings may have no effect, or several different property settings may all have the same effect. Settings outside the accepted range may produce an error. For more information, see the manufacturer's documentation for the specific driver.

I hope thease will help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.