I have created an excel userform to record pallets of rejected product on a production line. The user fills in details and prints out a label to insert on the pallet of rejected product. On occasion, the production line may be able to reuse rejected product within the production area and there is a checkbox on my form which the user ticks if this is the case. The code then makes some extra textboxes visible and prints a label as before.
My code works for the straightforward case where one pallet is rejected and is to be reused. Where I encounter problems is if, for example, 2 pallets of rejects are created but only one pallet is to be reused and the other to be scrapped. I want to print one label without the extra textboxes and one label with said textboxes.
The code below is not giving me any error messages but it is not printing when the case is = true and NoCopies (textbox) > 1.
I'm self-taught when it comes to VBA so may be going at this completely the wrong way and I'm not sure where to go next as I have tried a number of things e.g. two consecutive for loops : For p = 1 to p = prnt then For p = prnt+1 to NoCopies.Value and similar Do Until statements with no joy - either nothing prints or only one of the For statements run. I get no error messages. Any help to point me in the right direction is greatly appreciated
My code works for the straightforward case where one pallet is rejected and is to be reused. Where I encounter problems is if, for example, 2 pallets of rejects are created but only one pallet is to be reused and the other to be scrapped. I want to print one label without the extra textboxes and one label with said textboxes.
The code below is not giving me any error messages but it is not printing when the case is = true and NoCopies (textbox) > 1.
I'm self-taught when it comes to VBA so may be going at this completely the wrong way and I'm not sure where to go next as I have tried a number of things e.g. two consecutive for loops : For p = 1 to p = prnt then For p = prnt+1 to NoCopies.Value and similar Do Until statements with no joy - either nothing prints or only one of the For statements run. I get no error messages. Any help to point me in the right direction is greatly appreciated
Code:
Private Sub checkandprint()
Dim p As Integer
Dim prnt As Variant
'print set number of copies, set background to white and make save and print button invisible
CommandButton1.Visible = False
Complex_ETicket_pt4.BackColor = vbHighlightText
For i = 1 To 11
Controls("Label" & i).BackColor = vbHighlightText
Next i
Select Case CheckBox1.Value
Case Is = False
CheckBox1.Visible = False
Label11.Visible = False
Spraybox.Visible = False
For p = 1 To NoCopies.Value
Me.ScrollBars = fmScrollBarsNone
Complex_ETicket_pt4.PrintForm
Next p
'if there is a multi print and they are reusing, find out
'how many pallets are being reused and print/spray the correct details
Case Is = True And NoCopies.Value > 1
prnt = Round(Application.InputBox("How many pallets are to be used within the cell?", Type:=1), 0)
If NoCopies.Value <> prnt Then
For p = 1 To p = NoCopies.Value
While p <= prnt
CheckBox1.Visible = True
CheckBox1.BackColor = vbHighlightText
Label11.Visible = True
Spraybox.Visible = True
If p > 1 Then
Spraybox.Value = Spraybox.Value + 1
End If
Me.ScrollBars = fmScrollBarsNone
Complex_ETicket_pt4.PrintForm
Wend
While p > prnt
CheckBox1.Visible = False
Label11.Visible = False
Spraybox.Visible = False
Me.ScrollBars = fmScrollBarsNone
Complex_ETicket_pt4.PrintForm
Wend
Next p
Else
CheckBox1.Visible = True
CheckBox1.BackColor = vbHighlightText
Label11.Visible = True
Spraybox.Visible = True
Me.ScrollBars = fmScrollBarsNone
Complex_ETicket_pt4.PrintForm
End If
Case Is = True And NoCopies.Value = 1
CheckBox1.Visible = True
CheckBox1.BackColor = vbHighlightText
Label11.Visible = True
Spraybox.Visible = True
Me.ScrollBars = fmScrollBarsNone
Complex_ETicket_pt4.PrintForm
End Select
CommandButton1.Visible = True
End Sub