update tbname set 包装号=Dcount("*","tbname","运单号=" & 运单号 & " and 包装号<=" & 包装号)作者: yanwei82123300 时间: 2013-1-19 21:00
todaynew 老师您理解错了!请看1楼的例子吧!
窗体“批量拆分命令”点击后将数据生成到tblPacktemp表中
但是现在发现一个问题:运单号(ShipmentNO)9402,只能拆分2个(包装号),其他不能拆分,包装号断号(只填充了前两个,后面的没有填充)。 作者: koutx 时间: 2013-1-21 09:07
看这一句:
For ii = rst1.Fields("PackageNo") To rst1.Fields("Order_Qty") / rst1.Fields("UNITS_PER")
除了前两个PackageNo之外,其余的rst1.Fields("PackageNo") 都大于rst1.Fields("Order_Qty") / rst1.Fields("UNITS_PER")了,当然不会接着拆分了。
不清楚你的PackageNo、Order_Qty、UNITS_PER 这三者的关系? 作者: koutx 时间: 2013-1-21 09:18
如此改一下估计可以了:
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 作者: koutx 时间: 2013-1-21 09:29
For ii = rst1.Fields("PackageNo") To rst1.Fields("PackageNo") + (rst1.Fields("Order_Qty") / rst1.Fields("UNITS_PER")) - 1
此句也可改为:
For ii=1 to rst1.Fields("Order_Qty") / rst1.Fields("UNITS_PER")作者: yanwei82123300 时间: 2013-1-21 12:29
koutx 老师谢谢您的帮助!问题是我没有说细:
我想将包装号中的断号补齐(包装号(PackageNo)
并将新的包装号生成到CreatNo字段中
请看tblPackinglist:运单号ShipmentNO:9402