Solved

How to avoid a runtime error 91, object variable or with block variable not set ?

Posted on 2008-10-23
8
349 Views
Last Modified: 2013-11-27
I am developing an Access MDB application. In the application I call a Sybase Stored Procedure and return the result set to a recordset. I can only call this Stored Procedure. I do not own this Stored Procedure.

In a prior application I performed a Sybase Stored Procedure with the following code:
--------------------------------------------------------------------------------------------------------------------
Set oConn = CreateObject("ADODB.Connection")
oConn.Open "DSN=PRPT1;" & _
 "Uid=ina2;" & _
 "Pwd=rkName"
Set cmd = New ADODB.Command
With cmd
    .ActiveConnection = oConn
    .CommandType = adCmdText
    .CommandText = "exec getTATGATCDSAByAccount @ApplnNm='test', @accountNumber='019228238'"
    .CommandText = .CommandText & ",@accountSystem=1435,@selectFields='accountNumber, accountStatus"
    .CommandText = .CommandText & ", fullName1, address1, city, stateCode, postalCode, taxID, accountClassification"
    .CommandText = .CommandText & ", fullName2, countryCode, countryOfResidence, countryOfCitizenship, accountCategory"
    .CommandText = .CommandText & ", cashIndicator, marginIndicator, codIndicator'"
    Set recNameAdress = .Execute
End With
-------------------------------------------------------------------------------------------------------------------------
When I set the breakpoint to the line"
"Set recNameAdress = .Execute" and then execute this line, I can issue the command
?recNameAddress.GetString and I will get back a record.
-------------------------------------------------------------------------------------------------------------------


However, when I use the following code to call the other Stored Procedure,
I set the breakpoint to the line:
"Set recNameAdress = .Execute"  
and then when I execute this line, I then display the recordset with the following command:
?recNameAddress.GetString and I will get the following error:

Runtime error 91
Object Variable or With Block Variable not set
---------------------------------------------------------------------

Set oConn = CreateObject("ADODB.Connection")

oConn.Open "DSN=NYQ_DIG;" & _
 "Uid=PClie;" & _
 "Pwd=p4tX"
   
Set cmd = New ADODB.Command
With cmd
    .ActiveConnection = oConn
    .CommandType = adCmdText
    .CommandText = "exec sp3D_GetListOfDocuments 1"    '(the parameter 1 signifies that I want 1 record)
    Set recNameAddress = .Execute
End With
0
Comment
Question by:zimmer9
  • 5
  • 3
8 Comments
 
LVL 29

Accepted Solution

by:
Badotz earned 500 total points
ID: 22807223
Possibly because there is no data returned from the query?

First, you use this format:

.CommandText = "exec getTATGATCDSAByAccount @ApplnNm='test', @accountNumber='019228238'"

Next, you try this format:

.CommandText = "exec sp3D_GetListOfDocuments 1"

Possibly your syntax is wrong?
0
 
LVL 29

Expert Comment

by:Badotz
ID: 22826906
Ah, the strong, silent type, eh?

So, what, exactly, was the problem? Was it simply a syntax error?

It is always nice to hear from the Asker when a solution is accepted. In this case, we assume it was syntax, but one never knows.

Oh, and no worries - glad to help.
0
 

Author Comment

by:zimmer9
ID: 22826919
Believe it or not, I was informed to remove the Exec statement when calling the stored procedure and that works.

For ex:

.CommandText = "sp3D_GetListOfDocuments 1"
0
 
LVL 29

Expert Comment

by:Badotz
ID: 22826962
If what I proposed was not the solution, then why did you award me points and a grade?
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:zimmer9
ID: 22826990
You were the only one who responded to my inquiry and I felt it was my prerogative to award you points. You did help.
0
 
LVL 29

Expert Comment

by:Badotz
ID: 22827026
OK - just as long as you know it is not mandatory to award points.

If you decide there is no solution, just delete the question. Participants get four days to comment before the question is *really* closed.
0
 

Author Comment

by:zimmer9
ID: 22827035
I also modified the code to use:

.CommandType = adCmdStoredProc

thanks for your assistance and for pointing out some of the guidelines   :)
0
 
LVL 29

Expert Comment

by:Badotz
ID: 22827070
No worries.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now