Results 1 to 11 of 11
  1. #1
    Axel is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Apr 2018
    Posts
    12

    Deselect listbox items .

    Hello All,


    How do I deselect the selected listbox items when clicked outside in the form?

    Thank you in advance

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    I presume you mean after you have clicked a cmd button or run a VBA function, rather than simply clicked anywhere else?

    Have a read here http://allenbrowne.com/func-12.html
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    Axel is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Apr 2018
    Posts
    12
    Simply clicked somewhere else.

  4. #4
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    Well the same code / technique applies - But how do you know you've dealt with the selection(s) made from the listbox?
    If you have code acting on the On_Click property you may as well deselect it then, if not and you have an "Action" button to do something with the selected item(s) - add the code to that.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Try this:

    Code:
    Private Sub lstChosen_Exit(Cancel As Integer)
        Dim varItem As Variant
        For Each varItem In lstChosen.ItemsSelected
            lstChosen.Selected(varItem) = False
        Next
    End Sub

  6. #6
    Axel is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Apr 2018
    Posts
    12
    Thank you for the solution but i tried a more simple one. I used the on key press event and used the code Me.listBox.Value = Null. It worked.

  7. #7
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Quote Originally Posted by Axel View Post
    Thank you for the solution but i tried a more simple one. I used the on key press event and used the code Me.listBox.Value = Null. It worked.
    I couldn't get that to work. What control captured the key press (key press where)?

    Edit: I see. The event procedure would have to be in every control that might have the focus.
    Last edited by davegri; 05-15-2018 at 12:01 PM.

  8. #8
    Axel is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Apr 2018
    Posts
    12
    Sorry but I did not understand your Edit part. I just selected the on key press event and plugged in the code.

  9. #9
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    You could put it in the Details Event section of the form. That will fire if there is no control.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  10. #10
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Sorry but I did not understand your Edit part. I just selected the on key press event and plugged in the code.
    Axel, code has to be associated with some control or object. Where did you plug in the code? On key press of what?

    You could put it in the Details Event section of the form. That will fire if there is no control.
    Minty, there is no on key press event for the detail section.

  11. #11
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    @Dave - Damn should have checked. Good spot.

    I'm perplexed by the apparent solution as well to be honest, it's not how I would have done it.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Adding all items in ListBox
    By Voodeux2014 in forum Programming
    Replies: 12
    Last Post: 11-10-2015, 01:31 PM
  2. how to de-select items in a listbox
    By CharbelKahi in forum Programming
    Replies: 1
    Last Post: 06-23-2014, 07:05 AM
  3. Tallying a listbox's items
    By lyrasphere in forum Access
    Replies: 3
    Last Post: 05-22-2014, 08:12 AM
  4. prevent deselect items in the listbox after right click
    By masoud_sedighy in forum Programming
    Replies: 1
    Last Post: 08-13-2013, 01:06 AM
  5. Replies: 8
    Last Post: 05-24-2011, 03:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums