Sandcastor
Board Regular
- Joined
- May 14, 2012
- Messages
- 97
I've built a custom print box userform, with the help of quite a few of the gurus here.
I'm using Von Pookie's code to parse the checkboxes in the form, and iterate an input box so the user can type how many copies of each checked form to print. I'm currently working on the "Sample Labels" button, because it is the easiest, and will add other buttons from there. (Checkboxes 4-12 are disabled for debugging)
The problem I am finding is that since using a For-Loop to fill the Variables, the inputboxes will not accept the number 2 as a response. Every other value works. And 2 is the most likely value to be entered in the box. Full script follows, probem area highlighted.
I have tweaked the code about six times, modified the error handlers, adjusted variable placement, and tried Integer, Long, and Variant variable types, always with the same result.
Help, please?

I'm using Von Pookie's code to parse the checkboxes in the form, and iterate an input box so the user can type how many copies of each checked form to print. I'm currently working on the "Sample Labels" button, because it is the easiest, and will add other buttons from there. (Checkboxes 4-12 are disabled for debugging)
The problem I am finding is that since using a For-Loop to fill the Variables, the inputboxes will not accept the number 2 as a response. Every other value works. And 2 is the most likely value to be entered in the box. Full script follows, probem area highlighted.
Code:
Private Sub PrintSampleLabels_Click()
Dim CBox As Control
Dim i As Long
Dim P As Variant
Dim N(12) As Variant
Dim NS As Variant
Dim answer
Dim Message, Title, Default
Title = "Print Copies" 'Set title.
Default = "2" 'Set default.
NS = InputBox("How many sheets of labels for the injection well?", "Print Copies")
If NS = vbCancel Then NS = 0
[COLOR=#800000]For i = 1 To 12
On Error Resume Next
Set CBox = Me.Controls("Offset" & i)
If CBox.Value = False Then
P = 0
GoTo Nextbox
End If
P = InputBox("How many sheets of labels for offset well #" & i & "?", "Print Copies")
If P = vbCancel Then P = 0
N(i) = CInt(P)
Nextbox:
Next i
[/COLOR]
If WorksheetFunction.Sum(N) + NS = 0 Then GoTo TheEnd
answer = MsgBox("Load " & WorksheetFunction.Sum(N) + NS & " sheets of blank Sample Labels into the printer.", vbOKCancel, "LABELS!")
If answer = vbCancel Then Exit Sub ' the macro ends if the user selects the CANCEL-button
Application.ScreenUpdating = False
If NS = 0 Then GoTo Skip
Sheets("SCHEM Sample Labels").PrintOut copies:=NS, Collate:=True, Preview:=False 'ActivePrinter:=
Skip:
For i = 1 To 12
Set CBox = Me.Controls("Offset" & i)
If CBox.Value = True And N(i) > 0 Then Sheets("SCHEM OFFSET " & i & " Labels").PrintOut copies:=N(i), Collate:=True, Preview:=False 'ActivePrinter:=
Next i
TheEnd:
Application.ScreenUpdating = True
End Sub
I have tweaked the code about six times, modified the error handlers, adjusted variable placement, and tried Integer, Long, and Variant variable types, always with the same result.
Help, please?
Last edited: