更新时间:2021-11-02 09:14:01
在不知道出现错误的那一行的情况下,我认为这是在本节中
Without knowing what line you are getting the error on I assume it is in this section
rst.MoveFirst
With Me.ListBox1
.Clear
Do
.AddItem rst![Department]
rst.MoveNext
Loop Until rst.EOF
End With
我会进行这些更改.
If rst.recordcount > 0 then
rst.MoveFirst
End if
With Me.ListBox1
.Clear
Do while rst.eof = false
.AddItem rst![Department]
rst.MoveNext
Loop
End With
我还建议对您的记录集使用锁.查看adLockOptimistic和adlockpessimistic.
I would also suggest using a lock on your recordset. Look into adLockOptimistic and adlockpessimistic.
rst.Open strSQL, cnn, adOpenStatic, adLockOptimistic
要回答您的最后一条评论,我将尝试声明不同的对象.并不是说您的操作方式有什么问题,因为它不会产生任何错误.尝试这样
To answer your last comment I would try declaring the objects different. Not that there is anything wrong with the way you did it since it didn't produce any errors. Try like this
Dim cnn As new adodb.connection
Dim rst As new adodb.recordset
这是早期绑定.因此,您可以取出set cnn = CreateObject()和set rst = CreateObject() 看看有没有人能找到你.
This is early binding. So you can take out the set cnn=CreateObject() and set rst=CreateObject() See if that get's you anywhere.