我想从" ASN_importdata"中逐行拆分纸箱。到新表" ASN_importdata2" 但结果不是我的预期。 有人可以帮我解决这个问题吗?
Source_ASN_Importdata:
CNO SKU QTY GW
---------------------------------
Y.01-03 AAA 600 60
Y.04 AAB 100 10
Y.04 AAC 100 10
Y.05-07 ABC 600 60
预期:
CNO SKU QTY GW
---------------------------------
01 AAA 200 20
02 AAA 200 20
03 AAA 200 20
04 AAB 100 10
04 AAC 100 10
05 ABC 200 20
06 ABC 200 20
07 ABC 200 20
实际结果:
CNO SKU QTY GW
---------------------------------
01 AAA 300 30
03 AAA 300 30
04 AAB 100 10
04 AAC 100 10
05 ABC 300 30
07 ABC 300 30
代码:
Private Sub txtconvert_Click()
Dim db As DAO.Database
Dim rsSource As DAO.Recordset
Dim rsOut As DAO.Recordset
Dim SplitToRows() As String
Dim I As Integer
Dim strCTN As String
Set db = CurrentDb
Set rsSource = db.OpenRecordset("ASN_Importdata")
Set rsOut = db.OpenRecordset("ASN_Importdata2")
If (Not rsSource.BOF And Not rsSource.EOF) Then
Do Until rsSource.EOF
strCTN = Replace(rsSource!cno, "Y.", "")
SplitToRows = Split(strCTN, "-", -1)
For I = 0 To CInt(UBound(SplitToRows()))
rsOut.AddNew
rsOut("CNO") = SplitToRows(I)
rsOut("SKU") = rsSource("SKU")
rsOut("QTY") = rsSource("QTY") / (UBound(SplitToRows()) + 1)
rsOut("GW") = rsSource("GW") / (UBound(SplitToRows()) + 1)
rsOut.Update
Next I
rsSource.MoveNext
Loop
MsgBox "Done!"
Else
MsgBox "No record"
End If
rsSource.Close
Set rsSource = Nothing
rsOut.Close
Set rsOut = Nothing
Set db = Nothing
End Sub