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
[2060 byte] By [HermanTabbert] at [2007-11-20 0:38:36]
# 1 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
PeejAvery at 2007-11-9 19:57:06 >
# 2 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
HermanTabbert at 2007-11-9 19:58:10 >
# 3 Re: Run-time error 91: Object variable or With block variable not set
Could you attach the form that contains that object?
PeejAvery at 2007-11-9 19:59:01 >
# 4 Re: Run-time error 91: Object variable or With block variable not set
Aren't you missing this line 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.
Shuja Ali at 2007-11-9 20:00:07 >
# 5 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
HermanTabbert at 2007-11-9 20:01:10 >
# 6 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/vbasic/vb_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_formatted_xml_file.html
Shuja Ali at 2007-11-9 20:02:15 >
# 7 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
HermanTabbert at 2007-11-9 20:03:08 >