Solved

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

Posted on 2008-10-23
8
358 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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
 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

685 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