如何统计Access列中的单词? 示例我有33个单词" Rec" " NoRec"我希望数字显示在两个文本框中,一个用于Rec,另一个用于NoRec。
答案 0 :(得分:1)
Access列是访问表的一列。因此,您选择该表的所有行,将所需的列添加到字符串中并计算该字符串中的单词数。假设该列为myColumn
且该表为myTable
:
Private Sub Test()
Dim dbs As Database
Dim rst1 As Recordset
Dim s As String
Set dbs = CurrentDb
With dbs
' Select all records
Set rst1 = .OpenRecordset("SELECT myColumn FROM myTable;", dbOpenDynaset)
While (Not rst1.EOF)
s = rst1.Fields("myColumn")
' now analyse s
'
rst1.MoveNext
Wend
rst1.Close
End With
Set dbs = Nothing
End Sub
答案 1 :(得分:1)
我认为您不需要VBA来执行此操作,您可以使用TOTALS
查询来获得所需的结果。
SELECT
Sum(IIF(yourColumnName = "Rec", 1, 0)) As TotalRec,
Sum(IIF(yourColumnName = "NoRec", 1, 0)) As TotalNonRec
FROM
YourTableName