I have a listbox with code that runs after user makes a selection (clicks item). It's a Form Control (vs. ActiveX type).
Right now, while the code runs (takes about 5 seconds to complete), user can immediately click another item on list and listbox selection changes (though click event doesn't re-run since it's still completing initial run). RESULT: If user clicks X then clicks Y while first click run, list has item Y selected but results of CLICK event's code show data/results from item X.
Instead of displaying a temporary warning telling user not to click another list item, I'd like to prevent the listbox from being changed until the first click's event code finishes. I've tried adding the following to the beginning of the listbox's CLICK event but no success:
1) Adding .enabled = false or .locked = false.
2) Used DoEvents after enable/lock code but no improvement
3) Tried moving focus out of list before disabling and locking. I
4) Adding Application.EnableEvents = False at beginning of event
If I run code to disable listbox for testing (no CLICK event running), it's disabled correctly. So I know my code is valid. The change just doesn't take place during the listbox's CLICK event's code.
And, when stepping through code, then Immediate Window shows enabled value is actually false after line runs but, again, the user still is able to click listbox and change selection.
How can I prevent lisbox changes while CLICK event runs?
Seems like this should be simple. What am I missing???
Maybe some creative alternative way to achieve this goal?
Right now, while the code runs (takes about 5 seconds to complete), user can immediately click another item on list and listbox selection changes (though click event doesn't re-run since it's still completing initial run). RESULT: If user clicks X then clicks Y while first click run, list has item Y selected but results of CLICK event's code show data/results from item X.
Instead of displaying a temporary warning telling user not to click another list item, I'd like to prevent the listbox from being changed until the first click's event code finishes. I've tried adding the following to the beginning of the listbox's CLICK event but no success:
1) Adding .enabled = false or .locked = false.
2) Used DoEvents after enable/lock code but no improvement
3) Tried moving focus out of list before disabling and locking. I
4) Adding Application.EnableEvents = False at beginning of event
If I run code to disable listbox for testing (no CLICK event running), it's disabled correctly. So I know my code is valid. The change just doesn't take place during the listbox's CLICK event's code.
And, when stepping through code, then Immediate Window shows enabled value is actually false after line runs but, again, the user still is able to click listbox and change selection.
How can I prevent lisbox changes while CLICK event runs?
Seems like this should be simple. What am I missing???
Maybe some creative alternative way to achieve this goal?
Last edited: