DragonRebornRand
asked on
Missing node results in object variable not set error
I am parsing through an xml file using VBA in MS access, and sometimes a particular node isnt in the xml file, and sometimes it is.
when I use the code below, if the "Phone" node isnt there, then I recieve an error that the Object Variable is not set. Is there a way to skip the code line if the object doesnt exist, or skip the line if the error occurs?
FundPhone = xmlDoc.documentElement.sel ectSingleN ode("Phone ").text
when I use the code below, if the "Phone" node isnt there, then I recieve an error that the Object Variable is not set. Is there a way to skip the code line if the object doesnt exist, or skip the line if the error occurs?
FundPhone = xmlDoc.documentElement.sel
Can you post the entire code please?
Sometimes you need a syntax like this:
Dim x as SomeObject
Set x=SomeValue
So presuming that you declared xmlDoc somewhere (and declared it correctly), ...you might need to do this:
Set FundPhone = xmlDoc.documentElement.sel ectSingleN ode("Phone ").text
Sometimes you need a syntax like this:
Dim x as SomeObject
Set x=SomeValue
So presuming that you declared xmlDoc somewhere (and declared it correctly), ...you might need to do this:
Set FundPhone = xmlDoc.documentElement.sel
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
My suggestion is to check for null before you attempt to use the variable:
Set node = xmlDoc.documentElement.selectSingleNode("Phone")
If Not node Is Nothing Then
FundPhone = .text
End If
Line 4 should have included "node":
FundPhone = node.text
ASKER
Error Handling works. Thanks mbizup
Open in new window