retrieving listbox values

austin350s10

Active Member
Joined
Jul 30, 2010
Messages
321
Ok so I am working on a userform that contains a listbox with 3 columns in it (bound column = 0). I'm filling this listbox from a database using .additem. When I attempt the retrieve the first columns selected value I am unable to do so. The MultiSelect property of the listbox is set to: 0 - fmMultiSelectSingle Hoping someone understands this better than I.

My Attempt:
Code:
Private Sub clientList_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

Dim myClientID As String

' I tried each of the 3 methods below with no luck
myClientID = clientList.List(clientList.ListIndex, 0)         ' GIVES ME:  Run time error 381: Could not get the List property.  Invalid property array index.
myClientID = clientList.Value                                     ' GIVES ME:  Run time error 94:  Invalid use of Null
myClientID = clientList.Column(0, clientList.RowSource) ' GIVES ME:  Run time error 381: Could not get the List property.  Invalid property array index.

MsgBox myClientID

End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
This should work...

myClientID = clientList.List(clientList.ListIndex, 0)

The error may occur when nothing is selected in the list. This would test if anything is selected.

Code:
    [color=darkblue]If[/color] clientList.ListIndex > -1 [color=darkblue]Then[/color]
        myClientID = clientList.List(clientList.ListIndex, 0)
    [color=darkblue]Else[/color]
        MsgBox "Nothing selected"
    [color=darkblue]End[/color] [color=darkblue]If[/color]
 
Upvote 0
If it's just one value you want then you can use the Value property, provided the column which contains the value is the BoundColumn of the listbox.
 
Upvote 0
This is slightly off topic, but I noticed that .BoundColumn is usually a 1 based property.
When .BoundColumn = 0, the .Value property returns the same as the .ListIndex
 
Upvote 0
Thank you....def a retard...lol The first part of my code resets the list. so that why I could get the selected value....WOW
 
Upvote 0
I've done that plenty of times.:oops:
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,851
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top