我有一个表单,允许用户键入50个不同的部件号,并打印出每个部件号需要打印的标签数量。我遇到的问题是,当我将部件号发送到标签报告时,标签数量不正确。这就是我所拥有的:
Private Sub cmdPrint_Click()
'Printing multiple labels for one record
Dim i As Integer
Dim a As Integer
Dim rst As ADODB.Recordset
Dim total As Integer
Set rst = New ADODB.Recordset
'Delete previous label data
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE FROM [tmpParts]"
DoCmd.SetWarnings True
On Error GoTo errHandler
'Catch blank QTY
'If set to 0, label report is blank but runs
If IsNull(Me!QTY) Then
MsgBox "Please enter the quantity for labels", _
vbOKOnly, "Error"
DoCmd.GoToControl "QTY"
Exit Sub
End If
rst.Open "[tmpParts]", CurrentProject.Connection, adOpenDynamic,
adLockPessimistic
'Adds duplicate records for selected item using input value
For total = 1 To Total_QTY.Value
For i = 1 To QTY.Value
With rst
.AddNew
!Item_Number = Me.Combo_1.Column(1)
!Item_Description = Me.Item_Desc
!Bin = Me.Bin_Loc
.Update
End With
Next i
For j = 1 To QTY_2.Value
With rst
.AddNew
!Item_Number = Me.Combo2.Column(1)
!Item_Description = Me.Item_2
!Bin = Me.Bin_2
.Update
End With
Next j
Next total
DoCmd.OpenReport "rptTemporaryLabels", acViewPreview
'DoCmd.PrintOut
'DoCmd.RunCommand acCmdClose
rst.Close
Set rst = Nothing
Exit Sub
errHandler:
MsgBox Err.Number & ": " & Err.Description, vbOKOnly, "Error"
DoCmd.SetWarnings True
rst.Close
Set rst = Nothing
End Sub
现在它还不完整,因为我只有2个数量的盒子只是为了测试目的。我试图这样做,如果QTY对于该部件号说3,而QTY_2对另一个部件号说2,那么标签将反映它。