Testing for <Object variable or With block variable not set>

I have a situation where a user is double clicking on a treeview node.  I need to test to see if the node is a root/parent or a child.  Currently, if the node is a child and has a parent the values TreeView1.SelectedItem.Parent.Text and TreeView1.SelectedItem.Key have a "value". If the parent end doesn't exist or the child is in fact a parent I get the error  <Object variable or With block variable not set>.

So, I'd like to test the parent to see if it's value is  <Object variable or With block variable not set>. HOWEVER, testing to see if it is "Nothing" or Null doesn't work.

Any ideas? This has been driving me crazy all day!!
LVL 1
digitalwavIT Infrastructure ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongCommented:
try like:

If TreeView1.SelectedItem Is Nothing Then Exit Sub

If Not TreeView1.SelectedItem.Parent Is Nothing Then 'Child Node is Clicked

Else 'Parent Node is Clicked

End If

?
   
0
Carl TawnSystems and Integration DeveloperCommented:
You can use the treeviews Expand event to check for a parent.
Something like:

    Private Sub TreeView1_Expand(ByVal Node As MSComctlLib.Node)

        If Not Node.Parent Is Nothing Then
            '// Node has parent
        Else
            '// Node doesn't have parent
        End If

    End Sub

Hope this helps.
0
Mikal613Commented:
on error goto SomeWhere:

SomeWhere:

If err.number = 91 then
   msgbox "HAHA you got 91"
end if
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

digitalwavIT Infrastructure ManagerAuthor Commented:
Excellent Idea, handle it via the error handler. Duh. BTW- the IS Nothings don't work with this for some reason.
0
Mikal613Commented:
yeah man you got me on that one thats why resolved to the error handling
0
Carl TawnSystems and Integration DeveloperCommented:
Then you're either not using the standard Microsoft control or you're not doing it right.  

Using the Is Nothing is the more correct and cleaner way of doing what you want.
Using error handlers where you don't need to is very untidy and sloppy.
0
Ryan ChongCommented:
Some Personal comment, just think that It's always NOT the best solution to handle your scripts and allow it to exit via Error Handler (unless is those such unexpected errors), while we can determine and comparing the logic (in this case the TreeView1.SelectedItem.Parent), means that you put a potential problem on your scripts, and the initial problem is still not yet resolved..
0
Mikal613Commented:
wow we started a war
0
digitalwavIT Infrastructure ManagerAuthor Commented:
It's true, the control is from VBAccellerator, but it returns the same error with the MS control.

I know it's not the best way, but the situation where that code will run is rarely used.  I am tagging it for a rewrite for the next version.
0
Mikal613Commented:
          _
                            _-' "'-,    
                         _-' | d$$b |  
                      _-'    | $$$$ |    
                   _-'       | Y$$P |  
                _-'|         |      |
             _-'  _*         |      |
          _-' |_-"      __--''\    /
       _-'         __--'     __*--'
     -'       __-''    __--*__-"`
    |    _--''   __--*"__-'`  
    |_--"  .--=`"__-||"  
    |      |  |\\   ||
    | .dUU |  | \\ //
    | UUUU | _|___//
    | UUUU |  |  
    | UUUU |  |        
    | UUUU |  |
    | UUUU |  |
    | UUUU |  |
    | UUP' |  |
    |   ___^-"`
     ""'          
0
Ryan ChongCommented:
See my profile, at the bottom of it:

::: Pray for World Peace :::

So, No war please, even at EE , cheers 8-)
0
digitalwavIT Infrastructure ManagerAuthor Commented:
Nice piece...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

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.