Runtime error 91, Object variable not set or with block variable not set

Posted on 2006-11-01
Medium Priority
Last Modified: 2013-12-26
       this is my code below and it throws the error 'Object variable or with block variable not set.'
       Global xmlDoc As DOMDocument
       Global intCounter As Integer
       Global xmlDataListTag  As IXMLDOMNodeList
       Global xmlDataTag  As IXMLDOMNodeList
       Global iCounter     As Integer
       Global itX          As IXMLDOMNode

       Set xmlDoc = New MSXML2.DOMDocument
       xmlDoc.loadXML strouxml
      Set xmlDataListTag = xmlDoc.getElementsByTagName("Exception")
      Set itX = xmlDataListTag.nextNode
      sOutput = itX.selectSingleNode("MainCode").Text---error occurs at this point.

this is very urgent please help me out....

Question by:lazziebob
LVL 13

Expert Comment

ID: 17855289
>>Set itX = xmlDataListTag.NextNode
here xmlDataListTag.NextNode returns blank to the itX

LVL 14

Expert Comment

by:Shiju Sasidharan
ID: 17855544
Try some extra handling
    Set itX = xmlDataListTag.nextNode
    If itX Is Nothing Then
        MsgBox "Node not found"
        Exit Sub ' or Exit Function
    End If
LVL 13

Expert Comment

ID: 17855566
LVL 12

Expert Comment

ID: 17895348
Is there a valid element called "MainCode" in the itX object?

If so, is it actually spelled as MainCode or is it in all lowercase or uppercase?
LVL 25

Accepted Solution

Lee Savidge earned 1500 total points
ID: 17914494

This error occurs in your situation because on of the objects you're creating is not being created properly. Step through the code with a breakpoint and just hover the mouse over the objects to see which ones are nothing. This line grabs my attention:

Set xmlDataListTag = xmlDoc.getElementsByTagName("Exception")

Firstly, does the node "Exception" exist? If it does, xml is case sensitive, so is it called EXCEPTION, exception, eXcepTion, etc.? If it does exist, does it return anything to xmlDataListTag? It's difficult to give much help without seeing more of the code.



Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

619 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