VBA 运行存储过程时出错 - 运行时错误 91 对象变量或未设置块

VBA Error while running Stored Proc - run time error 91 object variable or with block not set

我是 VBA 的新手,正在尝试调用 sybase ASE 存储过程并取回结果集,这就是我正在做的事情。运行时我在打开连接 (dbCon.Open connectionString) 的行收到错误 "run time error 91 object variable or with block not set",任何人都可以提供一些指示吗?

Sub GetEmployees()
    Dim dbCon As ADODB.Connection
    Dim rstTemp As New ADODB.Recordset
    Dim query As String
    Dim connectionString As String
    query = "exec sp"
    connectionString = "Driver=Sybase.ASEOLEDBProvider;Server Name=serverName,port;
    Initial Catalog=DBname;User id=user;Password=pass;"
    dbCon.Open connectionString
    dbCon.CommandTimeout = 600
    rstTemp.Open query, dbCon, adOpenForwardOnly
End Sub

您需要实例化您的 Connection 对象。

使用其中之一:

Dim dbCon As New ADODB.Connection

Dim dbCon As ADODB.Connection
Set dbCon = New ADODB.Connection