Double click item in Listbox to select item and close Listbox

G

GusEvans

Have a large complicated VBA Project in which the first item after it starts
is displaying a Listbox with 30 items (single select). Now the user must
select the item and click the OK Button (it works). But from a windows GUI
viewpoint they should be able to just double click the desired item and have
it work the same as select and click OK. I have looked all through the
Properties Window but see nothing to make it work. Just want to make it work
like a real Windows App.
XP Pro - Excel 2003

Any help (even if can't be done) would be appreciated.
 
R

Rick Rothstein \(MVP - VB\)

Have a large complicated VBA Project in which the first item after it
starts
is displaying a Listbox with 30 items (single select). Now the user must
select the item and click the OK Button (it works). But from a windows
GUI
viewpoint they should be able to just double click the desired item and
have
it work the same as select and click OK. I have looked all through the
Properties Window but see nothing to make it work. Just want to make it
work
like a real Windows App.
XP Pro - Excel 2003

Assuming your OK button is an ActiveX control named CommandButton1 for this
example (user your actual control's name, of course), just put this one line
in the ListBox's DoubleClick event...

CommandButton1_Click

and double clicking an item will do the same as selecting an item and
clicking the CommandButton.


Rick
 
G

GusEvans

Great - worked like a charm!
--
Gus Evans


Rick Rothstein (MVP - VB) said:
Assuming your OK button is an ActiveX control named CommandButton1 for this
example (user your actual control's name, of course), just put this one line
in the ListBox's DoubleClick event...

CommandButton1_Click

and double clicking an item will do the same as selecting an item and
clicking the CommandButton.


Rick
 
I

Incidental

Hi Gus

You could do it using code like that listed below

Option Explicit
Dim LstSelection As String

Private Sub CommandButton1_Click()
Call DoYourThingHere
End Sub

Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Call DoYourThingHere
End Sub

Sub DoYourThingHere()
LstSelection = ListBox1.Value
MsgBox LstSelection
ListBox1.Visible = False
End Sub

hope this helps

S
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top