0
votes

I am new to VBA and trying to call a sybase ASE stored proc and get the result set back, this is what i am doing. While running i am getting error "run time error 91 object variable or with block not set" at line opening the connection (dbCon.Open connectionString), can anyone please provide some pointers ?

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
1
Try Dim dbCon As New ADODB.Connection - silentsurfer
Will also want to do a similar thing for the recordset - Michael Petch

1 Answers

2
votes

You need to instantiate your Connection object.

Use either:

Dim dbCon As New ADODB.Connection

or

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