Hello All,
How do I deselect the selected listbox items when clicked outside in the form?
Thank you in advance
Hello All,
How do I deselect the selected listbox items when clicked outside in the form?
Thank you in advance
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 ↓↓
Simply clicked somewhere else.
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 ↓↓
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
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.
Sorry but I did not understand your Edit part. I just selected the on key press event and plugged in the code.
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 ↓↓
Axel, code has to be associated with some control or object. Where did you plug in the code? On key press of what?Sorry but I did not understand your Edit part. I just selected the on key press event and plugged in the code.
Minty, there is no on key press event for the detail section.You could put it in the Details Event section of the form. That will fire if there is no control.
@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 ↓↓