Reputation: 1601
I'm trying to return a value from my code. It's much easier to just show the code:
Function writeHeaderData() As IXMLDOMNode
Dim xmlDoc As New MSXML2.DOMDocument30
xmlDoc.async = False
xmlDoc.LoadXML "<Foo></Foo>"
Dim Foo As IXMLDOMNode
Set Foo = xmlDoc.DocumentElement
'code snip; includes appending lots of things to Foo
'the error is on this line:
writeHeaderData = Foo
Exit Function
End Function
I've already Google searched, but it's been of no avail. This function is being called from the main subroutine, and I'm trying to append the returned IXMLDOMNode to a bigger one, but I keep getting an "Object variable or With block variable not set
" error on the writeHeaderData = Foo
line. What's up here?
Upvotes: 4
Views: 5644
Reputation: 63378
In VB(A), when you want to assign to an object variable, including assigning the return value of a function, you need to use Set
, so:
'the error is on this line:
writeHeaderData = Foo
should be
Set writeHeaderData = Foo
Upvotes: 9