access中如何将一张表按字段拆分成多张表
举例说明:
1.要求按照地址分组,按人统计工资总额,比如
北京:H张 200
广东:H李:400
湖南:C张:100
湖南:U红:200
江苏:Y三:600
2.分别生成北京表,广东表,湖南表,江苏表。
3.在一窗体上建一按钮Command0,在其单击事件中写上以下代码:
Private Sub Command0_Click()
Dim sql As String
Dim rst As New ADODB.Recordset
Dim strNO As String
sql = "select * from 地址依据 "
rst.Open sql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
rst.MoveFirst
For i = 1 To rst.RecordCount
If rst!地址 <> strNO Then
dz = rst!地址
CurrentDb.Execute "select """ & rst!姓名 & """ AS 姓名,""" & rst!工资总计 & """AS 工资总计 into [" & dz & "]"
strNO = rst!地址
Else
CurrentDb.Execute "insert into [" & dz & "](姓名,工资总计) select """ & rst!姓名 & """,""" & rst!工资总计 & """"
End If
rst.MoveNext
Next
rst.Close
Set rst = Nothing
End Sub
5.单击此按钮即生成了三个表。