遍历数据表追加到汇总表(ACCESS 自写代码备忘)

Attribute VB_Name = "模块2" Sub Total() Dim Conn As New ADODB.Connection Dim Rec As New ADODB.Recordset Dim rsTemp As New ADODB.Recordset Dim strSQL As String With Conn .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:/TotalData.mdb; " .Open End With strSQL = "select * from 汇总表" Rec.Open strSQL, Conn, adOpenKeyset, adLockPessimistic If Rec.RecordCount > 0 Then Conn.Execute "Delete * from 汇总表" End If Set Rec = Nothing '判断有几张数据表 Set rsTemp = Conn.OpenSchema(adSchemaTables) Do While Not rsTemp.EOF Debug.Print rsTemp!TABLE_NAME If Left(rsTemp!TABLE_NAME, 1) <> "~" And Left(rsTemp!TABLE_NAME, 4) <> "MSys" And rsTemp!TABLE_NAME <> "汇总表" Then strSQL = "Insert into 汇总表 select * from " & rsTemp!TABLE_NAME Conn.Execute strSQL strSQL = "UPDATE 汇总表 SET 汇总表.tablename = " & "'" & rsTemp!TABLE_NAME & "'" & " Where 汇总表.tablename is null " Conn.Execute strSQL rsTemp.MoveNext Else rsTemp.MoveNext End If Loop Set rsTemp = Nothing Set Rec = Nothing End Sub

 

做个记录。自己看的。

你可能感兴趣的:(遍历数据表追加到汇总表(ACCESS 自写代码备忘))