|
假设结果表名称为 A
Dim rs As New ADODB.Recordset
Dim rst As New ADODB.Recordset
Dim strSQL As String
Dim lngArray() As Long
Dim i As Long, j As Integer
Dim k As Integer
strSQL = "select t_id from tb_out where t_id mod 3=0 order by t_id"
With rs
.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockReadOnly
ReDim lngArray(.RecordCount - 1) As Long
For i = 0 To .RecordCount - 1
lngArray(i) = .Fields(0)
.MoveNext
Next
.Close
rst.Open "A", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
For i = 0 To UBound(lngArray)
strSQL = "select * from tb_out where t_id between " & lngArray(i) & _
" and " & lngArray(i) & "+2"
.Open strSQL, CurrentProject.Connection, adOpenKeyset, _
adLockReadOnly
rst.AddNew
Do While Not .EOF
For j = 0 To .Fields.Count - 1
rst.Fields(j + k) = .Fields(j)
Next
.MoveNext
k = k + .Fields.Count
Loop
.Close
rst.UpdateBatch
k = 0
Next
End With
rst.Close
Set rst = Nothing
Set rs = Nothing |
|