?
Solved

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

Posted on 2004-11-09
12
Medium Priority
?
366 Views
Last Modified: 2010-05-02
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!!
0
Comment
Question by:digitalwav
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 55

Expert Comment

by:Ryan Chong
ID: 12536924
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
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 12537151
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
 
LVL 48

Accepted Solution

by:
Mikal613 earned 2000 total points
ID: 12537188
on error goto SomeWhere:

SomeWhere:

If err.number = 91 then
   msgbox "HAHA you got 91"
end if
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:digitalwav
ID: 12537277
Excellent Idea, handle it via the error handler. Duh. BTW- the IS Nothings don't work with this for some reason.
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12537306
yeah man you got me on that one thats why resolved to the error handling
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 12537307
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
 
LVL 55

Expert Comment

by:Ryan Chong
ID: 12537350
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
 
LVL 48

Expert Comment

by:Mikal613
ID: 12537399
wow we started a war
0
 
LVL 1

Author Comment

by:digitalwav
ID: 12537409
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
 
LVL 48

Expert Comment

by:Mikal613
ID: 12537454
          _
                            _-' "'-,    
                         _-' | d$$b |  
                      _-'    | $$$$ |    
                   _-'       | Y$$P |  
                _-'|         |      |
             _-'  _*         |      |
          _-' |_-"      __--''\    /
       _-'         __--'     __*--'
     -'       __-''    __--*__-"`
    |    _--''   __--*"__-'`  
    |_--"  .--=`"__-||"  
    |      |  |\\   ||
    | .dUU |  | \\ //
    | UUUU | _|___//
    | UUUU |  |  
    | UUUU |  |        
    | UUUU |  |
    | UUUU |  |
    | UUUU |  |
    | UUP' |  |
    |   ___^-"`
     ""'          
0
 
LVL 55

Expert Comment

by:Ryan Chong
ID: 12537467
See my profile, at the bottom of it:

::: Pray for World Peace :::

So, No war please, even at EE , cheers 8-)
0
 
LVL 1

Author Comment

by:digitalwav
ID: 12537473
Nice piece...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question