|
如此改一下估计可以了:
Sub 拆分() ''经典的将表数据批量追加到另一表中
On Error Resume Next
Dim S As Integer
Dim rst1 As adodb.Recordset
Dim str1 As String
str1 = "SELECT * FROM tblPackinglist"
Set rst1 = New adodb.Recordset
rst1.Open str1, CurrentProject.Connection, adOpenStatic, adLockReadOnly
If rst1.RecordCount > 0 Then
rst1.MoveFirst
For i = 1 To rst1.RecordCount
S = 1 'Format(ii, "000")
For ii = rst1.Fields("PackageNo") To rst1.Fields("PackageNo") + (rst1.Fields("Order_Qty") / rst1.Fields("UNITS_PER")) - 1
DoCmd.RunSQL "INSERT INTO tblPacktemp SELECT '" & S & "' AS CreatNo, '" & rst1.Fields("ShipmentNO") & "' AS ShipmentNO, " & rst1.Fields("PackageNo") & " AS PackageNo, '" & rst1.Fields("Order_Qty") & "' AS Order_Qty,'" & rst1.Fields("ItemNumber") & "' AS ItemNumber,'" & rst1.Fields("ItemDescription") & "' AS ItemDescription,'" & rst1.Fields("UNITS_PER") & "' AS UNITS_PER,'" & rst1.Fields("CONumber") & "' AS CONumber, '" & rst1.Fields("Line") & "' AS Line"
' DoCmd.OpenQuery "qryUpdate表1desc"
'DoCmd.RunSQL "INSERT INTO 表1 SELECT '" & S & "' AS 序号, '" & rst1.Fields("ITEM") & "' AS item, " & rst1.Fields("QTY") & " AS qty, '" & rst1.Fields("MO") & "' AS mo"
S = S + 1
Next
rst1.MoveNext
Next
End If
End Sub
|
|