May 29 2006, 11:12 AM
On a number of forms I don't have room for a multiselect listbox. So, I've simulated a multiselect combobox (not listbox) using the following method.
1) Place a textbox on the form.
2) Immediately to the right of the textbox place a button of similar size to the Access combobox arrow button and with a picture of an arrow on it.
3) Below the textbox place a multiselect listbox that will be displayed and or hidden depending on when the user clicks on the 'arrow' button.
When a user clicks on the 'arrow' button, the multiselect listbox is displayed. The user can select as many entries as desired. When one entry is selected, the textbox shows that entry. If more than one entry is selected, then the phrase 'Multiple Selections Made' appears in the textbox.
This all works fine. But currently the listbox does not disappear after the last selection is made. I have to click on an area outside the listbox (somewhere else on the form) in order to have code execute to set the listbox visible property to no. This is accomplished in the Detail and Form Header On Click events. However, this is not intuitive because a normal combobox closes it's "list box portion" after a user releases the mouse button.
The multiselect property of the listbox that is being made visible and invisible is set to 'Extended'. So multiple selections need to be made by holding down the 'Shift' or 'Ctrl' keys or by dragging the mouse. Seems like I should be able to cause my listbox to disappear by using an event (mouse and keyboard) if the user releases either the shift or ctrl key or releases the mouse button.
I've never been clear on how these events works so any help is greatly appreciated.
May 29 2006, 12:19 PM
You can use some of the events you have mentioned but you can *not* set the visible property of the control with the focus to FALSE. First you need to move the focus elsewhere on your form.
May 29 2006, 12:57 PM
Thanks for reminding me about that.
But I'm having some problems with these events. For example, if I hold the Ctrl key or shift down and start making selections with the mouse, if I have a MouseUp event that causes the listbox to become invisible, I can't make more than one selection. How do I handle this??
May 29 2006, 01:31 PM
How are you assigning the value from the listbox to the textbox?
Seems to me that would be the place to set the listbox's visible
May 29 2006, 02:24 PM
I'm using the AfterUpdate event of the Listbox. But I believe it's getting fired after every change regardless of whether or not the shift or ctrl keys are being held down. When just dragging the mouse, however, it looks like the AfterUpdate event gets fired after the mouse button is released.
So I don't think this will work for setting the listbox visible property.
May 29 2006, 06:46 PM
It's a bit of a kludge, but you can use the same method many people
use for roll-over effects with labels and buttons.
Declare a private form level variable
Private ListIsVisible As Boolean
Then in the listbox's mousemove event put:
ListIsVisible = True
And then the Details Mousemove event put:
If Not ListIsVisible Then Exit Sub
Me.lstSimulatedCombo.Visible = False
ListIsVisible = False
All you have to do is make sure there is enough space between the listbox and
other controls so that the mouse cursor will hit the detail section of the form
when it leaves the listbox area. You can also add the Detail Mousemove code to
any controls that may be so close that they prevent the Detail mousemove event
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here