【发布时间】:2013-12-27 00:36:51
【问题描述】:
真诚地在黑暗中。我的代码:
Public Property Get rowCount() As Integer
rowCount = Counter
End Property
Public Property Let rowCount(ByRef inte As Integer)
Counter = inte
End Property
Private Sub Form_Timer() 'Timer
Dim dbs As DAO.Database
Dim rs As DAO.Recordset
Dim Caption As Field, Form As Field, Count As Integer, holder As Integer, item As String
Dim strForms() As String
Set dbs = CurrentDb
Set rs = dbs.OpenRecordset("MainMenu", dbOpenDynaset)
ReDim strForms(1 To rs.RecordCount())
If rs.RecordCount <> 0 Then
For c = 1 To rs.RecordCount() Step 1 '!!!THIS IS THE PROBLEM!!!
MsgBox CStr(c)
MsgBox rs("Caption")
strForms(c) = rs("Caption")
rs.MoveNext
MsgBox rs("Caption")
Next c
End If
rowCount = 1
holder = rowCount()
If holder <= rs.RecordCount() Then
Me.Command10.Caption = strForms(holder)
rowCount = holder + 1
Else
rowCount = 1
Me.Command10.Caption = strForms(holder)
End If
End Sub
我添加了所有这些消息框以进行调试。我只需要那个计数器上升。不知道为什么不是。为什么这个东西不会增加?!
【问题讨论】:
-
不,不是,它陷入了无限循环。此外,如果数据集为空,它甚至不会进入 for 循环。
-
首次构建 RS 时,
RecordCount属性不准确,因此您的循环计数器永远不会正确。最好使用Do Until Rs.EOF方法。计数不准确,因为将它们拖到客户端进行计数需要开销 - Access 在本地 RS 上执行相同的操作,直到滚动到视图/查询/视图的末尾才显示准确的 RecordCount。