当前位置: 代码迷 >> VBA >> VBA 阵列索引超出范围
  详细解决方案

VBA 阵列索引超出范围

热度:5351   发布时间:2013-02-26 00:00:00.0
VBA 阵列索引超出范围 求助
请问各位VBA大侠,运行此段代码,当intcount=21时,提示“阵列索引超出范围”,无法再运行下去,如何解决呢?


Public Function LoadFromDB(Connection As sqlDB, SQL As String, _
FieldName As String, Optional NameField As String = "", Optional Append As Boolean = True) As Integer
  Dim objRS As Recordset, intCount As Integer
  Dim strtemp As String
   
  Set objRS = Connection.OpenRecordset(SQL)
  If Not objRS Is Nothing Then
  If Not Append Then Clear
  intCount = 0
  While Not objRS.EOF
  AddItem objRS(FieldName), IIf(NameField = "", IsNull(objRS(FieldName)), IsNull(objRS(NameField)))
   
  intCount = intCount + 1
  objRS.MoveNext
  Wend
  Connection.CloseRecordset objRS
  LoadFromDB = intCount
  Else
  LoadFromDB = -1
  End If
End Function


------解决方案--------------------------------------------------------
请问,这个问题你到最后解决了吗?我也遇到了同样的问题。。。