Results 1 to 5 of 5
  1. #1
    SSSlippy is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    5

    Issue with label printing

    My issue is it will print the previous label instead of the current one when hitting print. If anyone has an idea of why this happens or how I can fix it would be appreciated.
    All users are hard wired on 1GB network and all files are on SSD machines.
    How the setup works:
    Each box we ship gets a # for that order. Example 1-100. I then verify that there is product on the order with the box #. I then verify if a label has not be printed before. I then mark the product on the order as printed. We have 3 different printing orders based on a selection on the screen. I also have a per user setting on what label print they print to so that they do not have to hit a print confirmation screen every time they print a label. After printing it updates some fields shown to the user to help them keep track of where they are in the packing process.



    Code:
    
    Public Function LabelPrint() As Variant
    
    
       Dim strSQL        As String
       Dim intBoxCount   As String
       Dim intLabelCheck As Integer
       Dim intResponse   As Integer
       Dim strDefaultPrinter  As String
    
    
       On Error GoTo ErrorHandler
    
    
        If IsNull(txtBox) Then
            MsgBox "Need a box number to print.", , "Box Number"
            Exit Function
        End If
        DoCmd.RunCommand acCmdSaveRecord
        'Verify any product is assigned to box number
        intBoxCount = Nz(DCount("[BoxNumber]", "[tblOrderDetail]", "[BoxNumber] = " & txtBox & " and [OrderID] = " & txtOrderID & ""), 0)
        If intBoxCount > 0 And txtBox > 0 Then
            'Check if label has been printed before and check if user still wants to print
            intLabelCheck = Nz(DCount("[ShipmentLabelPrint]", "[tblOrderDetail]", "[BoxNumber] = " & txtBox & " and [OrderID] = " & txtOrderID & " and [ShipmentLabelPrint] = -1"), 0)
            If intLabelCheck > 0 Then
                intResponse = MsgBox("Do you want to reprint the label?", vbYesNo + vbQuestion, "Reprint Label?")
                If intResponse = vbNo Then
                    Exit Function
                End If
            End If
            'Mark line item as label printed
            strSQL = "UPDATE tblOrderDetail SET tblOrderDetail.ShipmentLabelPrint = True " & _
                     vbCrLf & "WHERE (((tblOrderDetail.OrderID)=" & txtOrderID & ") AND ((tblOrderDetail.BoxNumber)=" & txtBox & "));"
            CurrentDb.Execute strSQL, dbFailOnError
            'Print in subcategory then product order
            If txtLabelOrder = 1 Then
                DoCmd.OpenReport "rptShipmentLabelPackProd", acViewPreview
                DoCmd.SelectObject acReport, "rptShipmentLabelPackProd"
                'get current default printer.
                strDefaultPrinter = Application.Printer.DeviceName
                'switch to printer per user config
                Set Application.Printer = Application.Printers(Forms!frmLogin!cboPrinter.Column(1))
                DoCmd.PrintOut , , , , 1
                'reset back to default
                Set Application.Printer = Application.Printers(strDefaultPrinter)
                'Update user displayed fields
                txtBox = txtBox + 1
                'Get the amount of boxes packed so far
                txtBoxesPacked = Nz(DCount("[BoxNumber]", "[qryfrmOrderBoxPutAway]"), 0)
                'Get the next box that should be packed
                txtLastBox = ELookup("BoxNumber", "tblOrderDetail", "BoxNumber Is Not Null and [OrderID] = " & txtOrderID & "", "BoxNumber DESC")
                DoCmd.Close acReport, "rptShipmentLabelPackProd"
            End If
            'Print in code order
            If txtLabelOrder = 2 Then
                DoCmd.OpenReport "rptShipmentLabelPackCode", acViewPreview
                DoCmd.SelectObject acReport, "rptShipmentLabelPackCode"
                'get current default printer.
                strDefaultPrinter = Application.Printer.DeviceName
                'switch to printer per user config
                Set Application.Printer = Application.Printers(Forms!frmLogin!cboPrinter.Column(1))
                DoCmd.PrintOut , , , , 1
                'reset back to default
                Set Application.Printer = Application.Printers(strDefaultPrinter)
                'Update user displayed fields
                txtBox = txtBox + 1
                'Get the amount of boxes packed so far
                txtBoxesPacked = Nz(DCount("[BoxNumber]", "[qryfrmOrderBoxPutAway]"), 0)
                'Get the next box that should be packed
                txtLastBox = ELookup("BoxNumber", "tblOrderDetail", "BoxNumber Is Not Null and [OrderID] = " & txtOrderID & "", "BoxNumber DESC")
                DoCmd.Close acReport, "rptShipmentLabelPackCode"
            End If
            'Print in category order
            If txtLabelOrder = 3 Then
                DoCmd.OpenReport "rptShipmentLabelPackCat", acViewPreview
                DoCmd.SelectObject acReport, "rptShipmentLabelPackCat"
                'get current default printer.
                strDefaultPrinter = Application.Printer.DeviceName
                'switch to printer per user config
                Set Application.Printer = Application.Printers(Forms!frmLogin!cboPrinter.Column(1))
                DoCmd.PrintOut , , , , 1
                'reset back to default
                Set Application.Printer = Application.Printers(strDefaultPrinter)
                'Update user displayed fields
                txtBox = txtBox + 1
                'Get the amount of boxes packed so far
                txtBoxesPacked = Nz(DCount("[BoxNumber]", "[qryfrmOrderBoxPutAway]"), 0)
                'Get the next box that should be packed
                txtLastBox = ELookup("BoxNumber", "tblOrderDetail", "BoxNumber Is Not Null and [OrderID] = " & txtOrderID & "", "BoxNumber DESC")
                DoCmd.Close acReport, "rptShipmentLabelPackCat"
            End If
        Else
            MsgBox "No product in this box number.  Unable to print blank label.", , "No Product"
        End If
    
    
    ExitRoutine:
       Exit Function
    
    
    ErrorHandler:
       LogError Err, Err.Description, "LabelPrint()", Me
       Resume ExitRoutine
    
    
    End Function


  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,088
    Can you please try this updated code? The code assumes the reports are using record sources that include only the labels you want to print.
    Code:
    Public Function LabelPrint() As Variant
    
    
       Dim strSQL        As String
       Dim intBoxCount   As String
       Dim intLabelCheck As Integer
       Dim intResponse   As Integer
       Dim strDefaultPrinter  As String
       Dim sReport as string
    
    
       On Error GoTo ErrorHandler
    
    
    
    
        If IsNull(txtBox) Then
            MsgBox "Need a box number to print.", , "Box Number"
            Exit Function
        End If
        DoCmd.RunCommand acCmdSaveRecord
        'Verify any product is assigned to box number
        intBoxCount = Nz(DCount("[BoxNumber]", "[tblOrderDetail]", "[BoxNumber] = " & txtBox & " and [OrderID] = " & txtOrderID & ""), 0)
        If intBoxCount > 0 And txtBox > 0 Then
            'Check if label has been printed before and check if user still wants to print
            intLabelCheck = Nz(DCount("[ShipmentLabelPrint]", "[tblOrderDetail]", "[BoxNumber] = " & txtBox & " and [OrderID] = " & txtOrderID & " and [ShipmentLabelPrint] = -1"), 0)
            If intLabelCheck > 0 Then
                intResponse = MsgBox("Do you want to reprint the label?", vbYesNo + vbQuestion, "Reprint Label?")
                If intResponse = vbNo Then
                    Exit Function
                End If
            End If
            'Mark line item as label printed
            strSQL = "UPDATE tblOrderDetail SET tblOrderDetail.ShipmentLabelPrint = True " & _
                     vbCrLf & "WHERE (((tblOrderDetail.OrderID)=" & txtOrderID & ") AND ((tblOrderDetail.BoxNumber)=" & txtBox & "));"
            CurrentDb.Execute strSQL, dbFailOnError
            Select Case txtLabelOrder
    	Case 1
    		sReport="rptShipmentLabelPackProd" 
    	Case 2
    		sReport="rptShipmentLabelPackCode"
    	Case 3
    		sReport="rptShipmentLabelPackCat"
    	End Select
    	
                'get current default printer.
                strDefaultPrinter = Application.Printer.DeviceName
                'switch to printer per user config
                Set Application.Printer = Application.Printers(Forms!frmLogin!cboPrinter.Column(1))
    	    DoCmd.OpenReport sReport, acViewNormal 'print the selected report
                'DoCmd.PrintOut , , , , 1
                'reset back to default
                Set Application.Printer = Application.Printers(strDefaultPrinter)
                'Update user displayed fields
                txtBox = txtBox + 1
                'Get the amount of boxes packed so far
                txtBoxesPacked = Nz(DCount("[BoxNumber]", "[qryfrmOrderBoxPutAway]"), 0)
                'Get the next box that should be packed
                txtLastBox = ELookup("BoxNumber", "tblOrderDetail", "BoxNumber Is Not Null and [OrderID] = " & txtOrderID & "", "BoxNumber DESC")
    
    
    
    
           
        Else
            MsgBox "No product in this box number.  Unable to print blank label.", , "No Product"
        End If
    
    
    
    
    ExitRoutine:
       Exit Function
    
    
    
    
    ErrorHandler:
       LogError Err, Err.Description, "LabelPrint()", Me
       Resume ExitRoutine
    
    
    
    
    End Function
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    SSSlippy is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    5
    So with just some basic testing the first issue I ran into was that the way it was printing was causing me to have margins cut off on the top and side.

    Normally the users PC has a default of whatever a standard laser print may be but the label printer is not the default. It seems to be using the margins from the drivers of the printer when using the way you advised to initiate the print. I change the code to below. Is there is a way to force the print to have using your method to zero margins on each side then I can make it work?

    Code:
    Public Function LabelPrint() As Variant
    
    
    
    
       Dim strSQL        As String
       Dim intBoxCount   As String
       Dim intLabelCheck As Integer
       Dim intResponse   As Integer
       Dim strDefaultPrinter  As String
       Dim sReport As String
    
    
       On Error GoTo ErrorHandler
    
    
        If IsNull(txtBox) Then
            MsgBox "Need a box number to print.", , "Box Number"
            Exit Function
        End If
        DoCmd.RunCommand acCmdSaveRecord
        'Verify any product is assigned to box number
        intBoxCount = Nz(DCount("[BoxNumber]", "[tblOrderDetail]", "[BoxNumber] = " & txtBox & " and [OrderID] = " & txtOrderID & ""), 0)
        If intBoxCount > 0 And txtBox > 0 Then
            'Check if label has been printed before and check if user still wants to print
            intLabelCheck = Nz(DCount("[ShipmentLabelPrint]", "[tblOrderDetail]", "[BoxNumber] = " & txtBox & " and [OrderID] = " & txtOrderID & " and [ShipmentLabelPrint] = -1"), 0)
            If intLabelCheck > 0 Then
                intResponse = MsgBox("Do you want to reprint the label?", vbYesNo + vbQuestion, "Reprint Label?")
                If intResponse = vbNo Then
                    Exit Function
                End If
            End If
            'Mark line item as label printed
            strSQL = "UPDATE tblOrderDetail SET tblOrderDetail.ShipmentLabelPrint = True " & _
                     vbCrLf & "WHERE (((tblOrderDetail.OrderID)=" & txtOrderID & ") AND ((tblOrderDetail.BoxNumber)=" & txtBox & "));"
            CurrentDb.Execute strSQL, dbFailOnError
            Select Case txtLabelOrder
        Case 1
            sReport = "rptShipmentLabelPackProd"
        Case 2
            sReport = "rptShipmentLabelPackCode"
        Case 3
            sReport = "rptShipmentLabelPackCat"
        End Select
                DoCmd.OpenReport sReport, acViewPreview
                DoCmd.SelectObject acReport, sReport
                'get current default printer.
                strDefaultPrinter = Application.Printer.DeviceName
                'switch to printer per user config
                Set Application.Printer = Application.Printers(Forms!frmLogin!cboPrinter.Column(1))
                DoCmd.PrintOut , , , , 1
                'reset back to default
                Set Application.Printer = Application.Printers(strDefaultPrinter)
                'Update user displayed fields
                txtBox = txtBox + 1
                'Get the amount of boxes packed so far
                txtBoxesPacked = Nz(DCount("[BoxNumber]", "[qryfrmOrderBoxPutAway]"), 0)
                'Get the next box that should be packed
                txtLastBox = ELookup("BoxNumber", "tblOrderDetail", "BoxNumber Is Not Null and [OrderID] = " & txtOrderID & "", "BoxNumber DESC")
                DoCmd.Close acReport, sReport
        Else
            MsgBox "No product in this box number.  Unable to print blank label.", , "No Product"
        End If
    
    
    ExitRoutine:
       Exit Function
    
    
    ErrorHandler:
       LogError Err, Err.Description, "LabelPrint()", Me
       Resume ExitRoutine
    
    
    End Function

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,088
    You can try to open each of the three reports in print preview, change the printer to either the default Microsoft Save as PDF or XPS printers that should be on each machine, change all the margins to 0 and save. Then try the code you have to change the printer and print the report.

    Cheers,
    Vlad

  5. #5
    SSSlippy is offline Novice
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    5
    Quote Originally Posted by Gicu View Post
    You can try to open each of the three reports in print preview, change the printer to either the default Microsoft Save as PDF or XPS printers that should be on each machine, change all the margins to 0 and save. Then try the code you have to change the printer and print the report.

    Cheers,
    Vlad
    So I attempted this and it did not work at all. Access kept trying to print to save as pdf. What I ended up doing was creating a dummy printer name one each machine with a copy of the settings needed. I then have it switch to whatever printer is needed. This seems like an ugly work around though.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. printing labels without the label wizard
    By philr in forum Reports
    Replies: 5
    Last Post: 04-06-2020, 12:24 PM
  2. Prevent label from printing on form
    By acrowe97 in forum Forms
    Replies: 2
    Last Post: 09-04-2018, 10:16 AM
  3. Selecting Start Position for label printing
    By halnurse in forum Reports
    Replies: 1
    Last Post: 05-23-2018, 12:27 PM
  4. Label printing problem
    By igiatakis in forum Queries
    Replies: 2
    Last Post: 09-13-2010, 08:27 AM
  5. Printing multiple copies of a mailing label
    By Flight Planner in forum Reports
    Replies: 1
    Last Post: 10-19-2006, 08:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums