Single-select Listbox drives me nuts (1 Viewer)

Solo712

Registered User.
Local time
Today, 18:45
Joined
Oct 19, 2012
Messages
828
I don't know whether this has been discussed on this or the VBA forum (I have not found any reference) but my single-select listbox (i.e. Multiselect property set to 'None') in Access 2007 drives me to distraction. I have tried everything but can't find a simple solution to reading out the single selection from the list. I have tried to read the collowing code trapped by OnClick and AfterUpdate events but it shows nothing was selected:

Code:
For i = 0 To CondoList.ListCount - 1
  If CondoList.Selected(i) Then
     If i <> glbCondoID - 1 Then
       '...........change the current selected condo to manage       
     End If
  End If
Next i

The code passes right through the items in the Listbox as if no selection was made. The 'CondoList.ItemsSelected.Count' shows a fat zero. Never had this problem with Multiselect !

The strangest thing is that if I query the listbox later (I created a radio button to confirm the new selection as a workaround) then it correctly identifies the selected item. Is this a bug or am I missing something ? I have tried just about everything. Many thanks for your help.
Best,
Jiri
 

Mr. B

"Doctor Access"
Local time
Today, 17:45
Joined
May 20, 2009
Messages
1,932
When the multi-select property of a listbox is set to "None" you do not have to iterate through the list to obtain the selected value. The selected value is simply the value in the listbox.

You can read the selected value by just asking for the value:

Me.condolist.value

In fact, you don't even have to use the ".value" you can just get the value by refering to the control:

Me.condolist

Assuming that you have a list of stinig values in your listbox, if you want to take some action dependent on a value being selected in the listbox, you can use:
Code:
If me.condolist > ""
     'take some action here
Else
     'take some other action here
End If
 

Solo712

Registered User.
Local time
Today, 18:45
Joined
Oct 19, 2012
Messages
828
When the multi-select property of a listbox is set to "None" you do not have to iterate through the list to obtain the selected value. The selected value is simply the value in the listbox.

You can read the selected value by just asking for the value:

Me.condolist.value

In fact, you don't even have to use the ".value" you can just get the value by refering to the control:

Me.condolist

Assuming that you have a list of stinig values in your listbox, if you want to take some action dependent on a value being selected in the listbox, you can use:
Code:
If me.condolist > ""
     'take some action here
Else
     'take some other action here
End If

Great ! I could have guessed it was something utterly trivial like that ! I relied on a piece of code written for the Multiselect option which was dumb. Strange though I have not found reference to this anywhere I looked.

Well, you solved the great mystery. Many thanks ! :)

Best,
Jiri
 

Users who are viewing this thread

Top Bottom