Private Sub hedui_Click()
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim aTEMP(3, 27) As String
Dim nTEMP(3, 27) As String
Dim i%, j%
Set conn = New ADODB.Connection
conn.CursorLocation = adUseClient
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\biaozhun.mdb"
Set rst = New ADODB.Recordset
Set rst.ActiveConnection = conni = 0
If biaozhun1.Text <> "" Then
rst.Open "Select * From biaozhun where steelgrade='" & steelgrade.Text & "' and biaozhun='" & biaozhun1.Text & "'"
For j = 2 To rst.Fields.Count - 1
If LTrim(rst.Fields(j)) <> "" Then
aTEMP(i, j / 2 - 1) = rst.Fields(j)
End If
j = j + 1
If LTrim(rst.Fields(j)) <> "" Then
nTEMP(i, (j - 1) / 2 - 1) = rst.Fields(j)
End If
Next j
rst.close
End Ifset rst=nothing
set conn=nothing
end sub
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim aTEMP(3, 27) As String
Dim nTEMP(3, 27) As String
Dim i%, j%
Set conn = New ADODB.Connection
conn.CursorLocation = adUseClient
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\biaozhun.mdb"
Set rst = New ADODB.Recordset
Set rst.ActiveConnection = conni = 0
If biaozhun1.Text <> "" Then
rst.Open "Select * From biaozhun where steelgrade='" & steelgrade.Text & "' and biaozhun='" & biaozhun1.Text & "'"
For j = 2 To rst.Fields.Count - 1
If LTrim(rst.Fields(j)) <> "" Then
aTEMP(i, j / 2 - 1) = rst.Fields(j)
End If
j = j + 1
If LTrim(rst.Fields(j)) <> "" Then
nTEMP(i, (j - 1) / 2 - 1) = rst.Fields(j)
End If
Next j
rst.close
End Ifset rst=nothing
set conn=nothing
end sub
但,再建議說明哪里的錯誤。看來是FIELDS的索引有誤,你詳細調試看看每個索引是否正確。
For j = 2 To rst.Fields.Count - 1
If LTrim(rst.Fields(j)) <> "" Then
aTEMP(i, j / 2 - 1) = rst.Fields(j)
End If
j = j + 1 '显然这里增加的话会使得下面FIELDS(J)越界
If LTrim(rst.Fields(j)) <> "" Then
nTEMP(i, (j - 1) / 2 - 1) = rst.Fields(j)
End If
Next j