Results 1 to 7 of 7
  1. #1
    Star Lounger
    Join Date
    Jun 2010
    Location
    Lichfield, UK
    Posts
    54
    Thanks
    10
    Thanked 0 Times in 0 Posts

    ListBox Click & DoubleClick events

    I'm developing an app in Access 2007 using VBA. I have a ListBox on a form and I want the code to execute Routine A if the list box is single clicked and Routine B if it is double clicked. I am really struggling to do what I thought would be simple.

    What actually happens is that if you click the ListBox then it fires the click event so I can run routine A from there. No problem.
    If you double click it fires both the Click and DoubleClick events so it executes Routines A and B which is not what I want.

    I tried setting flags in the Click and DoubleClick events thinking I could test the value of these flags in the AfterUpdate event and then decide which routine to run but it fires the AfterUpdate event before either the Click or DoubleClick event.

    Can anyone help me understand how I can get it to run Routine A on a click or Routine B on a double click.

    Many thanks

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    5,892
    Thanks
    0
    Thanked 83 Times in 79 Posts
    I would really suggest you don't use both click and double-click events on the same control. Is there a particular reason for that rather than a different event?
    Regards,
    Rory
    Microsoft MVP - Excel.

  3. #3
    Platinum Lounger
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    3,616
    Thanks
    7
    Thanked 231 Times in 219 Posts
    Single and double click on a control will confuse your users no end.

    cheers, Paul

  4. #4
    Star Lounger
    Join Date
    Jun 2010
    Location
    Lichfield, UK
    Posts
    54
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Thanks for the replies guys.

    I have a hierarchical data structure with records that can exist at up to 9 levels. Each record (apart from those at level 1) must have a parent and each record can have multiple children.

    I'm using the ListBox to allow the user to select the parent record when creating a new record. So when they go into the form the list box displays all current level 1 records.
    Double click on a row then goes down a level and shows all the children of the selected item.
    A single click will leave a row selected (ie that is the parent record the user wants). It will then display other data in other controls and the user moves on.
    I also have buttons to allow the user to move up 1 level and up to the top level.
    From a form design perspective this seemed neater than 1 list box per (up to 9) levels.
    If it cannot do it then I guess I'll have to add another button to navigate down a level - I've not done this as it will be slightly slower from the user's perspective.

    What really surprises me though is that VBA cannot handle this. Click and double click are clearly 2 distinct user actions so I'm surprised that it seems impossible to program different responses to each. I'm sure I've used applications in the past where this has been the case.

  5. #5
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    5,892
    Thanks
    0
    Thanked 83 Times in 79 Posts
    Why don't you use a Treeview? It's specifically designed for that.
    Regards,
    Rory
    Microsoft MVP - Excel.

  6. #6
    Star Lounger
    Join Date
    Jun 2010
    Location
    Lichfield, UK
    Posts
    54
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Thanks Rory

    I'll give it a go.

  7. #7
    Star Lounger
    Join Date
    Jun 2010
    Location
    Lichfield, UK
    Posts
    54
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Thanks again Rory.

    I eventually managed to get it working just as I want - there seems to be no documentation within Access to support it. I've just been trawling the internet to pick up snippets on what I needed to do but it was just the job.

    Cheers

Posting Permissions

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