Results 1 to 9 of 9
  1. #1
    New Lounger
    Join Date
    Feb 2003
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Treeview and expand event (Access 2002)

    Hi all,
    I'm using Access 2002 with a database in Access 2000 format in Windows XP
    home. I have a Treview control in a form, which I need to selectively make
    visible or not visible depending on some conditions. Also, I'm using the
    expand event to perform some operations. This works fine the first time,
    but if I set the "visible" property to False (in some cases I need to make
    this Treeview disappear from the screen), the next time I set "visible" to
    True, it causes the "expand" event to be triggered even if there were no
    expanded nodes before making the Tree invisible (weird, isn't it?). The worst part is that the
    expand event is triggered several times at this point.
    Any ideas about this behavior?

    Thanks in advance.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Treeview and expand event (Access 2002)

    I don't know of a way to *prevent* the Expand event to fire. Here is a way to get round it:
    <UL><LI>Declare a variable at the top of the form module

    Dim mblnUnhiding As Boolean

    <LI>In the code where you make the treeview control visible, set the variable to True immediately before, and to False immediately after it:

    If <condition> Then
    Me.TreeView1.Visible = False
    Else
    mblnUnhiding = True
    Me.TreeView1.Visible = True
    mblnUnhiding = False
    End If

    <LI>In the Expand event of the treeview control, check the variable:

    Private Sub TreeView1_Expand(ByVal Node As Object)
    If mblnUnhiding = False Then
    ' Your code goes here
    ...
    End If
    End Sub
    End Sub[/list]Note: a Boolean variable is False by default, it is only set to True temporarily while setting the treeview control to visible.

  3. #3
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Treeview and expand event (Access 2002)

    I don't know if this will help, but I've had some some success (in VB) setting the "top" property for a treeview to -1000 (or something) rather than making it invisible.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Treeview and expand event (Access 2002)

    Unfortunately, that doesn't work in Access. Trying to position a control outside the actual bounds of a form, even partially, raises an error message.

    Still, it was a good idea - it works in VB6. Access forms and controls are different from VB controls.

  5. #5
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Treeview and expand event (Access 2002)

    That is a pity.

    I rely on setting controls out of bounds in VB- even VB itself does the same with tab controls.

    Sorry I couldn't help, and thanks for the advice.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  6. #6
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Treeview and expand event (Access 2002)

    Hi,
    Can you set its height to 0 instead of making it invisible? That should not trigger the expand event when you set its height back to the original size.
    HTH.
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Treeview and expand event (Access 2002)

    Rory,

    It works in my test form. Much more elegant than my workaround!

    But why make things simple when you can make them more complicated instead? <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Treeview and expand event (Access 2002)

    VB forms don't have to function within the application window the way Access forms must, Geoff. And Access forms are easy to connect to data directly without the need for datacontrols. The tradeoffs are definitely worth it.
    Charlotte

  9. #9
    New Lounger
    Join Date
    Feb 2003
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Treeview and expand event (Access 2002)

    Rory,
    That definitely works. I already tried it in my application.
    Thanks to everybody for their comments and suggestions. Just in case it is of interest to someone, I found an interesting piece of code for canceling Treeview events such as node selection, expand and collapse in VB. I might try to make it work in VBA later. You can find it here:

    http://www.mvps.org/btmtz/treeview/

    Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •