答案 0 :(得分:0)
您在ListValues方法中缺少not语句。
Do While rs.EOF
应该是
Do While Not rs.EOF
答案 1 :(得分:0)
将Sub ListValues的代码更改为Directed:
Private Sub ListValues(ByVal db_file As String, ByVal db_table_name as String, ByVal
db_column_name As String)
Dim statement As String
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
'打开连接
Set conn = New ADODB.Connection
conn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & db_file & ";" & _
"Persist Security Info=False"
conn.Open
lstValues.Clear
Set rs = New ADODB.Recordset
rs.Open "SELECT*FROM " & db_table_name & " WHERE " & db_column_name, conn, adOpenStatic, adLockOptimistic
Do While Not rs.EOF
lstValues.AddItem rs.Fields(db_column_name).Value
rs.MoveNext
Loop
rs.Close
conn.Close
End Sub
编码中的另一个错误:
Your Code:
Set rs = conn.OpenSchema(adSchemaIndexes, _
Array(Empty, Empty, Empty, Empty,db_column_name))
Right code:
Set rs = conn.OpenSchema(adSchemaIndexes, _
Array(Empty, Empty, Empty, Empty,db_table_name))