|
- Private Sub Command3_Click()
- Dim rs As New ADODB.Recordset
- Dim strArray() As Long
- Dim strSQL As String
- Dim i As Long, j As Long
- Dim sSQL As String
- Dim strValues As String
- strSQL = "select 编号 from 表1 where 编号 mod 3=0 order by 编号"
- With rs
- .Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockReadOnly
- i = .RecordCount - 1
- ReDim strArray(i) As Long
- For i = 0 To .RecordCount - 1
- strArray(i) = .Fields(0)
- .MoveNext
- Next
- .Close
- For i = 0 To UBound(strArray)
- strSQL = "select top 3 * from 表1 where 编号<=" & strArray(i) & " order by 编号 desc"
- .Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockReadOnly
- .MoveLast
- Do While Not .BOF
- strValues = strValues & "'" & .Fields(1) & "',"
- .MovePrevious
- Loop
- If strValues <> "" Then
- strValues = Left(strValues, Len(strValues) - 1)
- End If
- j = j + 1
- sSQL = "insert into a(编号,字段1,字段2,字段3)values(" & j & "," & strValues & ")"
- CurrentDb.Execute sSQL
- strValues = ""
- .Close
- Next
- End With
- Set rs = Nothing
- Me.Child0.Requery
- End Sub
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|