1,105,281 Community Members

runtime error 91 object variable or With block variable not set

Member Avatar
ronb
Newbie Poster
1 post since Aug 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

i wrote and compiled an vb 6 program on a windows xp sp2 box
i am trying to run the program via a batch file from an nt box
i get this error:
runtime error 91:
object variable or With block variable not set
the program runs under the scheduler on xp, and in debug in vb ide
thanks in advance for the help

Member Avatar
Comatose
Taboo Programmer
2,536 posts since Dec 2004
Reputation Points: 290 [?]
Q&As Helped to Solve: 227 [?]
Skill Endorsements: 34 [?]
Team Colleague
 
1
 

It's possible that you are trying to create an instance of a class (an object) from a class that is present on the machines you tested it on, but not on the machine it's been deployed to..... for example, I happen to know that I can make a VB program utilize a class for Nero Burning Rom.... I can make a nero object, and use it's methods and properties...... but that will only work on machines that have the Nero libraries installed. If it's not installed, when you try to make the object (either through early or late bindings with new or createobject), the variable that SHOULD refer to the object is still set to Nothing, because the library failed to create an instance of the requested class.....

Basically, you are trying to make an object from a class that doesn't exist on the NT box.

Member Avatar
ibrahim refaat
Newbie Poster
1 post since Mar 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

when i want to setup certain program this messege appear

Member Avatar
PVBert
Junior Poster in Training
59 posts since Mar 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 5 [?]
Skill Endorsements: 0 [?]
 
0
 

in vb ide build an exe file
get a dependency walker and check which dependencies are needed for your exe file
create those dependencies on youre target machine
OR
get a setup (e.g. setupfactory) tool that builds a setup which does this for you
it can make a cabin file on development machine
that you can deploy on your target machine

Member Avatar
akodalikar
Newbie Poster
1 post since Jun 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

According to the MSDN library...
Error 91: Object variable or With block variable not set
---
There are two steps to creating an object variable. First you must declare
the object variable. Then you must assign a valid reference to the object
variable using the Set statement. Similarly, a With...End With block must be
initialized by executing the With statement entry point. This error has the
following causes and solutions:

You attempted to use an object variable that isn't yet referencing a valid
object.
Specify or respecify a reference for the object variable. For example, if
the Set statement is omitted in the following code, an error would be
generated on the reference to MyObject:

Dim MyObject As Object ' Create object variable.
Set MyObject = Sheets(1) ' Create valid object reference.
MyCount = MyObject.Count ' Assign Count value to MyCount.

You attempted to use an object variable that has been set to Nothing.
Set MyObject = Nothing ' Release the object.
MyCount = MyObject.Count ' Make a reference to a released object.

Respecify a reference for the object variable. For example, use a new Set
statement to set a new reference to the object.

The object is a valid object, but it wasn't set because the object library
in which it is described hasn't been selected in the References dialog box.
Select the object library in the Add References dialog box.

The target of a GoTo statement is inside a With block.
Don't jump into a With block. Make sure the block is initialized by
executing the With statement entry point.

i wrote and compiled an vb 6 program on a windows xp sp2 box
i am trying to run the program via a batch file from an nt box
i get this error:
runtime error 91:
object variable or With block variable not set
the program runs under the scheduler on xp, and in debug in vb ide
thanks in advance for the help

Member Avatar
avisek_cts
Newbie Poster
11 posts since Jun 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Private Sub Command1_Click()
Dim PDDoc As Object
Dim AVDoc As Object
Dim AcroExchApp As Object
Dim PDSaveFull As Object
AcroExchApp.GetActiveDoc
Set AcroExchApp = CreateObject("AcroExch.App")
AcroExchApp.GetActiveDoc
AVDoc.GetPDDoc
PDDoc.Save

Set PDDoc = AVDoc.GetPDDoc

If PDDoc.Save(PDSaveFull, "c:\test.pdf") = False Then
MsgBox "Unable to save image"
Else: MsgBox "The file is saved"
End If


End Sub

getting an error 91 whats wrong plzz help

Member Avatar
vb5prgrmr
Posting Virtuoso
1,670 posts since Mar 2009
Reputation Points: 143 [?]
Q&As Helped to Solve: 299 [?]
Skill Endorsements: 3 [?]
 
0
 

abisek_cts,

In the future please create your own thread and if you need to, copy the older threads url that you want to reference into your post.

Also please use code tags when submitting code. [ code ]your code goes here[ /code ] (without spaces as shown)

Now, I think you need to switch these two lines...

AcroExchApp.GetActiveDoc
Set AcroExchApp = CreateObject("AcroExch.App")

to

Set AcroExchApp = CreateObject("AcroExch.App")
AcroExchApp.GetActiveDoc

because you have not create the object yet and are trying to give it a command.


Good Luck

Member Avatar
avisek_cts
Newbie Poster
11 posts since Jun 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

will remeber it
can u send me the code what to write please...
the full code

Member Avatar
vb5prgrmr
Posting Virtuoso
1,670 posts since Mar 2009
Reputation Points: 143 [?]
Q&As Helped to Solve: 299 [?]
Skill Endorsements: 3 [?]
 
0
 

You posted the code...

Member Avatar
markperfinan
Newbie Poster
6 posts since Jul 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I don't think that you have to use the Set keyword because it is understood automatically by the compiler in assigning values to a variable. I also get the same problem but I think the error comes from the referencing of the assigned variable.

Member Avatar
pagos86
Newbie Poster
1 post since Oct 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

This particular error means that an invalid variable is being referenced within the code; in this case, the variable has been set to “nothing.” There’s not much that you can personally do about the program’s underlying code, however there are still possible ways to fix Runtime error 91 here.

Member Avatar
dspnhn
Junior Poster in Training
91 posts since May 2008
Reputation Points: 10 [?]
Q&As Helped to Solve: 14 [?]
Skill Endorsements: 0 [?]
 
0
 

i try and use a simpler approach like

set <object> = new <object instance>

Member Avatar
T-Wizard
Newbie Poster
2 posts since Feb 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
1
 

This error can also happen if you try to schedule a working executable. You can run it by double clicking, but scheduler gives you a '91' error. A work around is to have scheduler start a bat file to run the executable.

e.g. c:\scheduleMe.exe will run when you double-click it.
Task Scheduler running C:\scheduleMe fails '91'

RunScheduleMe.bat:
c:
cd \
run scheduleMe.exe

Task Scheduler running RunScheduleMe.bat works

Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 

Guys, ladies and so on, please note that this thread was started 2 years ago. I'm sure that the OP has found a solution by now, please do not raise the dead.;)

Member Avatar
T-Wizard
Newbie Poster
2 posts since Feb 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I found this thread from a search engine, trying to find a solution. I am sure that the original poster either solved his problem or switched careers. It is frustrating to search for solutions and not find them. I posted this solution to benefit future readers who have this problem.

Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 

Which is why I gave you some reputation points.:)

I agree, its irritating getting to a post with no solution, so thanks for the extra help.

Member Avatar
Sunnyrepairs
Newbie Poster
22 posts since Jul 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
0
 

Microsoft suggest that we can fix error 91 by creating a new registry key. To create a new key follow the steps below:

Click on Start
Type Regedit in the search box
Press Enter
Locate the following entry in the registry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Transaction Server
Now select the transaction server and right click on it
Select New and then choose Key
Name the key as Debug
Right click on the Debug key and choose New
Now select Key and name the key as RunWithoutContext
Ref: http://backspacetab.com/error-91/

Member Avatar
ChrisPadgham
Posting Pro in Training
450 posts since Sep 2009
Reputation Points: 113 [?]
Q&As Helped to Solve: 90 [?]
Skill Endorsements: 8 [?]
 
0
 

You need to use Set when you are assigning objects but not when you are assigning variables.

Member Avatar
visperad
Newbie Poster
1 post since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Private Sub button2_click()

'declare pp object
Dim pp As New PowerPoint.Application
' add a presentation variable
Dim pres As Presentation '("pres is a variable")

' add a slide for presentation

Dim sld As Slide '("pres is a name of a variable")

' addd a nw pp and set to "pres" variable


Set pres = pp.Presentations.Add

' add a new slide


sld = pres.Slides.Add(Index:=1, Layout:=ppLayoutTitle)


' fill in title
sld.Shapes(1).TextFrame.TextRange.Text = "sample report"

'take data from this workbook and add to peresentation
sld.Shapes(2).TextFrame.TextRange.Text = "Jane total;" ' take data from row4 and col 2

'save the presentation
pres.SaveAs "C:\Users\esarhes\Desktop\testpower.ppt"

' closepresentation
pres.Close

'clear memory
Set pp = Nothing
End Sub

I have a problem in the line of definding sld
it gives the error 91

Member Avatar
aronhugos
Newbie Poster
2 posts since Oct 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi, the error is usually caused by the Microsoft Visual Basic for Applications macro that searches for a specific fill color in Microsoft Excel. To fix the issue, just create a new registry key.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article