Getting single selected record from multiselect listbox

M

Max Moor

Hi All,

I have a multi select listbox that I use both as a single select and a
multi select. I can't change the multi select property in VB, so I keep a
software switch of my own, and trap the click event.

When getting multiple selected records, I use the standard, Access help
code:
For Each varItem In ctlItemList.ItemsSelected
Debug.Print ctlItemList.ItemData(varItem)
Next varItm

What I'm wondering is if there isn't a shorthand, maybe using the
ItemsSelected property, for getting row data when I know only one record is
selected? The code above would work, and just iterate once, but it seems a
lot of code to type to get one records data.

Thanks,
Max
 
J

Jeanette Cunningham

Max,
when it is in single select, do the same as with a combo box.
Use Me.ListBoxControlName to get the selected value, assuming you want the
ID from the hidden column.

Jeanette Cunningham
 
B

Bob Quintal

Hi All,

I have a multi select listbox that I use both as a single
select and a
multi select. I can't change the multi select property in VB, so
I keep a software switch of my own, and trap the click event.

When getting multiple selected records, I use the
standard, Access help
code:
For Each varItem In ctlItemList.ItemsSelected
Debug.Print ctlItemList.ItemData(varItem)
Next varItm

What I'm wondering is if there isn't a shorthand, maybe
using the
ItemsSelected property, for getting row data when I know only one
record is selected? The code above would work, and just iterate
once, but it seems a lot of code to type to get one records data.

Thanks,
Max
Why type when you can copy and paste?

Better yet, why not restructure your logic to use the same code.?
It's not difficult to do.
 
M

Max Moor

Max,
when it is in single select, do the same as with a combo box.
Use Me.ListBoxControlName to get the selected value, assuming you want the
ID from the hidden column.

Jeanette Cunningham

Hi Jeanette,
I would, but when it's in single select, it's really still in
multiselect. The multiselect property can't be changed from VB, so as far as
access is concerned, it in multi-mode all the time. Given that, the bound
column always returns null with that syntax.
-Max
 

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