第一个记录 A B F Q
第二个记录 B C A
第三个记录 B
第四个记录 B S C
......
B
C
J
H L A作者: todaynew 时间: 2009-12-19 14:33
字段中有若干人名,每人用空格分开,且顺序不固定。如何统计所有记录中每个人名出现次数 ?
如:下面字符分别代表汉字人名(两字或三字不等),人数不固定,之间有空格。
第一个记录 A B F Q
第二个记录 ...
boczsg 发表于 2009-12-18 14:54
[attach]40872[/attach]
[attach]40873[/attach]
Private Sub Form_Close()
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE * FROM 表2;"
End Sub
Private Sub 统计_Click()
Dim rs1 As New ADODB.Recordset
Dim rs2 As New ADODB.Recordset
Dim sql As String
Dim B As String
Dim i As Long
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE * FROM 表2;"
sql = "select * from 表1"
rs1.Open sql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
rs2.Open "表2", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
For i = 1 To rs1.RecordCount
B = rs1("人员")
Do While Nz(B, "") <> ""
rs2.AddNew
If InStr(B, " ") > 0 Then
rs2("姓名") = Mid(B, 1, InStr(B, " ") - 1)
B = Mid(B, InStr(B, " ") + 1)
Else
If InStr(B, " ") = 0 Then
rs2("姓名") = B
B = ""
End If
End If
rs2.Update
Loop
rs1.MoveNext
Next
rs1.Close
rs2.Close
Me.列表.Requery
End Sub