我在网上看了erase可以清空数组,但是我的代码只有在查询中才用到redim函数。上位机正常运行时没有使用查询操作,但是也会报那个错误。
Public Sub Find_date(ByVal Top As String, ByVal Down As String, ByVal i As Byte, ty As String, name As String)
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSQL As String, j As Integer, Z As Integer
DbPath = App.Path & "\T_data.mdb"
Constr = "provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & DbPath
con.Open Constr
sql = "SELECT COUNT(ID) as Z FROM Channels_1 WHERE ID between '" & Top & "' and '" & Down & "' and number='" & ty & " '
and Prj_name ='" & name & "'"
rs.Open sql, con, 3, 3
XXX = rs(Z)
con.Close
ReDim History(XXX)
ReDim Date_time(XXX)
con.Open
strSQL = " SELECT * FROM Channels_1 WHERE ID between '" & Top & "' and '" & Down & "'"
rs.CursorLocation = adUseClient
rs.Open strSQL, con, adOpenStatic, adLockBatchOptimistic
For Z = 1 To XXX
History(Z) = rs.Fields(Val(i)).Value
Date_time(Z) = rs.Fields(1).Value
rs.MoveNext
Next Z
con.Close
End Sub