|
如要一次将表中所有记录全拆到表1中,则不需窗体,写一SUB模块在需要调用的地方CALL即可:
Sub 拆分()
On Error Resume Next
Dim S As String
Dim rst1 As adodb.Recordset
Dim str1 As String
str1 = "SELECT * FROM tblMO"
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
For ii = 1 To rst1.Fields("QTY")
S = Format(ii, "000")
DoCmd.RunSQL "INSERT INTO 表1 SELECT '" & S & "' AS 序号, '" & rst1.Fields("ITEM") & "' AS item, " & rst1.Fields("QTY") & " AS qty, '" & rst1.Fields("MO") & "' AS mo"
Next
rst1.MoveNext
Next
End If
End Sub
|
|