感谢前面提供的有用的帮助,我有一种函数方法来计算记录集中字符串之间的单词频率。下面的代码产生所需的结果。
最后一步是将字典结构转储到currentDB中的Access表中。我可以像下面注释的那样逐个遍历每个键,并通过SQL附加到一个表中--但是它非常慢w/24K术语。
更新的>> w/解决方案<<
Private Sub Command0_Click()
Dim counts As New Scripting.Dictionary
Dim word As Variant
Dim desc As String
Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset '<< solution
Dim strSQL As String
Dim db As Database
Set db = CurrentDb
strSQL = "SELECT DISTINCT Items.Description FROM Items ;"
Set rs1 = db.OpenRecordset(strSQL, dbOpenDynaset)
Do While Not rs1.EOF
For Each word In Split(rs1!Description, " ")
If Not counts.Exists(word) Then
counts.Add word, 1
Else
counts.Item(word) = counts.Item(word) + 1
End If
Next
rs1.MoveNext
Loop
'>> .AddNew Solution inserted as suggested below <<
rs2 = db.OpenRecordset("Freq", dbOpenTable)
For Each word In counts.Keys
With rs2
.AddNew ' Add new record
.Fields!Term = word
.Fields!Freq = counts(word)
.Update
.Bookmark = .LastModified
End With
Next
rs2.Close
'>> End Solution <<
Set rs1 = Nothing
Set rs2 = Nothing
MsgBox "Done"
End Sub问题:
基本原理:使用表结构执行下游表示和操作更容易(对我来说)。
谢谢!
发布于 2016-09-14 13:53:01
您的代码没有显示您是如何尝试插入行的--我假设每一行都有单独的INSERT INTO (...) VALUES (...)语句?
对于一个循环中的多个插入,不要使用SQL语句。相反,将DAO.Recordset与.AddNew结合使用,速度会更快。
https://stackoverflow.com/questions/39491756
复制相似问题