我正在尝试从访问数据库中提取以下代码,但是收到错误91,请建议如何删除错误。
Private Sub CommandButton1_Click()
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strConn As String
Set con = New ADODB.Connection
con.Mode = adModeReadWrite
If con.State = adStateClosed Then
strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & "C:\temp\db2.mdb;Persist Security Info=False;"
con.ConnectionString = strConn
con.Open
End If
Dim startRow As Integer
***Set rs.ActiveConnection = con***
rs.Open "select * from tbl_name"
startRow = 3
Do Until rs.EOF
Cells(startRow, 4) = rs.Fields(0).Value
rs.MoveNext
startRow = startRow + 1
Loop
rs.Close
Set rs = Nothing
con.Close
Set con = Nothing
End Sub
答案 0 :(得分:3)
你打电话:
rs.ActiveConnection = con
rs.Open
没有首先创建RecordSet的实例:
Set rs = New ADODB.RecordSet
答案 1 :(得分:0)
我在测试应用程序时遇到此错误。
在我的特定情况下,应用程序使用的Oracle Home出现问题。因此,无法访问数据源。