出现运行时错误91 [对象变量或未设置块变量的情况] [英] getting run time error 91 [object variable or with block variable not set]
本文介绍了出现运行时错误91 [对象变量或未设置块变量的情况]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从访问数据库中提取以下代码,但出现错误91,请建议如何删除该错误。
i am trying the code below to pull from access db, but getting error 91, please suggest how to remove the error.
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
推荐答案
您致电:
rs.ActiveConnection = con
rs.Open
而无需先创建RecordSet的实例:
without first creating an instance of the RecordSet:
Set rs = New ADODB.RecordSet
这篇关于出现运行时错误91 [对象变量或未设置块变量的情况]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文