CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Feb 2003
    Location
    Holland
    Posts
    146

    Run-time error '91': Object variable or With block variable not set

    I get this error and have no idea how to solve it. I have been reading several treads on this forum abut this error but i cannot solve it.
    This is the start of my program:
    Dim Temp As Variant
    Dim AantalRec As Integer
    Dim oRoot As IXMLDOMElement
    Dim oElemVN As IXMLDOMElement
    Dim oElemBericht As IXMLDOMElement
    Dim oElemAdministratieveEenheid As IXMLDOMElement
    Dim oElemTijdvakAangifte As IXMLDOMElement
    Dim oElemTijdvakCorrectie As IXMLDOMElement
    Dim oElemVolledigeAangifte As IXMLDOMElement
    Dim oElemCollectieveAangifte As IXMLDOMElement
    Dim oElemSaldoCorrectiesVoorgaandTijdvak As IXMLDOMElement
    Dim oElemInkomstenverhoudingInitieel As IXMLDOMElement
    Dim oElemNatuurlijkPersoon As IXMLDOMElement
    Dim oElemAdresBinnenland As IXMLDOMElement
    Dim oElemAdresBuitenland As IXMLDOMElement
    Dim oElemInkomstenPeriode As IXMLDOMElement
    Dim oElemSectorRisocogroep As IXMLDOMElement
    Dim oElemNominatieveAangifte As IXMLDOMElement
    Dim OElemWgf As IXMLDOMElement
    Dim oElemData As IXMLDOMElement
    Dim oElemDataChild As IXMLDOMElement
    Dim oDocType As IXMLDOMDocumentType
    Dim intIDX As Integer
    Dim strXMLInstruct As String
    Dim oAttribute As IXMLDOMAttribute
    Dim oRootElem As IXMLDOMElement
    Dim oRootLoonAangifte As IXMLDOMElement
    ' Dim Opi As IXMLDOMProcessingInstruction
    Dim Tempbedrag As Single
    Dim Bedrag As Long
    Dim Bedrag1 As Single

    When running the program, the first part is doing good.
    But on this line:

    oElemTijdvakCorrectie.appendChild oElemInkomstenverhoudingInitieel


    i get the error.
    Who can help me?
    Regards,
    Herman

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Run-time error '91': Object variable or With block variable not set

    Could be that you are trying to reference a non-existent object. Are you sure that you have all the spelling right? That is a lot of characters. German is it?

    Take a look at the following URL.
    http://msdn2.microsoft.com/en-us/library/5szkzs17.aspx
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Feb 2003
    Location
    Holland
    Posts
    146

    Re: Run-time error '91': Object variable or With block variable not set

    No Peejavery, it is Dutch. (Holland). I am sure that the spelling is correct. I had already seen that URL. It did not help.
    Thanks for your reaction.
    Herman

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: Run-time error '91': Object variable or With block variable not set

    Could you attach the form that contains that object?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Run-time error '91': Object variable or With block variable not set

    Aren't you missing this line
    Code:
    Set oElemTijdvakCorrectie = New IXMLDOMElement
    You cannot reference something that has not been initialized. And to initialize an Object you need to use the New Keyword.

  6. #6
    Join Date
    Feb 2003
    Location
    Holland
    Posts
    146

    Re: Run-time error '91': Object variable or With block variable not set

    Thanks Shuja Ali.
    I placed that statement under the dim-statements and get an error:
    'Invalid use of New keyword'.
    Could you please tel me what i am doing wrong?

    Dim oRootElem As IXMLDOMElement
    Dim oRootLoonAangifte As IXMLDOMElement
    >> Set oElemTijdvakCorrectie = New IXMLDOMElement


    Thans in advance.
    Herman

  7. #7
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Run-time error '91': Object variable or With block variable not set

    Oh sorry for the previous post. That just came out of my mind directly. Anyaways, you need to learn the basidcs of how MS XML3 Parser works. Take a look at this article
    http://www.xml.com/pub/a/2000/07/12/...b_and_xml.html

    Now regarding your problem, you need to understand that the DOMElement belongs the DOMDocument. So without referecing a DOMDocument you cannot access the Element. Take a look at this sample
    http://vb-helper.com/howto_build_for..._xml_file.html

  8. #8
    Join Date
    Feb 2003
    Location
    Holland
    Posts
    146

    SOLVED Re: Run-time error '91': Object variable or With block variable not set

    Hi,
    My problem is solved:
    The wrong line should be:
    Set oElemInkomstenverhoudingInitieel = oDOM.createElement("InkomstenverhoudingInitieel")
    oElemTijdvakCorrectie.appendChild oElemInkomstenverhoudingInitieel
    Thanks everybody for the help.
    Greetings,
    Herman

  9. #9
    Join Date
    Sep 2009
    Posts
    1

    Re: Run-time error '91': Object variable or With block variable not set

    Hi,

    I have done one small project in vb using access, emp master data, bu i'm getting a error " Run-time error '91': Object variable or With block variable not set"

    here my code :

    Private Sub cb_save_Click()
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Set rs = db.OpenRecordset("select * from EMPICPL")

    If tb_desig.Text = "" Then
    MsgBox "PLEASE ENTER EMPLOYE NAME"
    tb_desig.SetFocus
    Else

    If tb_subd.Text = "" Then
    MsgBox "ENTER EMPLOYE ADDRESS"
    tb_subd.SetFocus
    Else
    If tb_basic.Text = "" Then
    MsgBox "ENTER EMPLOYE TALUKA"
    tb_basic.SetFocus
    Else


    'EMPLOYE CODE GENARATION
    If rs.EOF = False And rs.BOF = False Then
    rs.MoveFirst

    While (Not rs.EOF)

    txtempcode.Text = rs!EMP_CODE
    rs.MoveNext
    Wend
    txtempcode.Text = Val(txtempcode.Text) + 1

    End If


    If txtempcode.Text = "" Then
    txtempcode.Text = "1"
    End If

    rs.AddNew

    rs!desig = tb_desig.Text
    rs!SUbDepartment = tb_subd.Text
    rs!Basic = tb_basic.Text

    rs!EMP_CODE = txtempcode.Text


    rs.Update
    rs.Close

    txtempcode.Text = ""
    tb_desig.Text = ""
    tb_subd.Text = ""
    tb_basic.Text = ""

    End If
    End If
    End If

    End Sub

    please anyone can help me.

    thanks & regards

    vijay

  10. #10
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Run-time error '91': Object variable or With block variable not set

    This is a thread about XML. I suggest that you start another. Also, you need to use:
    Code:
    Code Tags
    so we can read your mess
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  11. #11
    Join Date
    Jan 2010
    Posts
    8

    Re: Run-time error '91': Object variable or With block variable not set

    same problem ..



    For I = 1 To flow.Count - 1 '->error "block variable not set"

  12. #12
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Run-time error '91': Object variable or With block variable not set

    pok3r824 Start a New thread please, as I'm closing this one

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured