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

Recommended Answers

All 19 Replies

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.

when i want to setup certain program this messege appear

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

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

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

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

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

You posted the code...

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.

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.

i try and use a simpler approach like

set <object> = new <object instance>

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

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.;)

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.

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.

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/

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

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.