![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
I have a ListBox called lstInventory, with two columns, a text value, and the ID primary key for that value. When I click an item in the listbox I would like to use that value to display details about that record based on the ID. This code never shows any item as selected, i.e. lstInventory.Selected(i) is always false - what is wrong with the code? Private Sub lstInventory_Click() Dim i As Integer i = -1 Do Until i = Me.lstInventory.ListCount i = i + 1 If lstInventory.Selected(i) Then Me!InventoryIDSelect = Me.lstInventory.Column(1, i) Loop End Sub |
#4
| |||
| |||
|
|
Try: Private Sub lstInventory_Click() If Me!lstInventory.ItemsSelected.Count = 0 Then MsgBox "Nothing's been selected." Else Me!InventoryIDSelect = Me!lstInventory.Column(1, Me!lstInventory.ItemsSelected(0)) End If End Sub That'll give you the value from the second column of the selected row. -- Doug Steele, Microsoft Access MVP http://www.AccessMVP.com/DJSteele Co-author: Access 2010 Solutions, published by Wiley (no e-mails, please!) "M Skabialka" <mskabialka (AT) NOSPAMdrc (DOT) com> wrote in message news:huo91h$fje$1 (AT) speranza (DOT) aioe.org... I have a ListBox called lstInventory, with two columns, a text value, and the ID primary key for that value. When I click an item in the listbox I would like to use that value to display details about that record based on the ID. This code never shows any item as selected, i.e. lstInventory.Selected(i) is always false - what is wrong with the code? Private Sub lstInventory_Click() Dim i As Integer i = -1 Do Until i = Me.lstInventory.ListCount i = i + 1 If lstInventory.Selected(i) Then Me!InventoryIDSelect = Me.lstInventory.Column(1, i) Loop End Sub |
#5
| |||
| |||
|
#6
| |||
| |||
|
|
the ID. This code never shows any item as selected, i.e. lstInventory.Selected(i) is always false - what is wrong with the code? |
#7
| |||
| |||
|
|
"M Skabialka" <mskabialka (AT) NOSPAMdrc (DOT) com> wrote: the ID. This code never shows any item as selected, i.e. lstInventory.Selected(i) is always false - what is wrong with the code? Because you're using Selected and not ItemData. Selected refers to the checkboxes which you can turn on or off. ItemData refers to the item you clicked. |
#8
| |||
| |||
|
|
Is it really helpful to crosspost to microsoft.public.access and CDMA? -- David W. Fenton http://www.dfenton.com/ usenet at dfenton dot com http://www.dfenton.com/DFA/ |
#9
| |||
| |||
|
|
After Microsoft announced the microsoft.public groups would be going away, I wasn't sure where I was going to get answers, so cross posted. I see now that probably won't be necessary. However I am not sure what you mean by CDMA. |
#10
| |||
| |||
|
|
"M Skabialka" <mskabialka (AT) NOSPAMdrc (DOT) com> wrote in news:hutbgr$u9i$1 (AT) speranza (DOT) aioe.org: After Microsoft announced the microsoft.public groups would be going away, I wasn't sure where I was going to get answers, so cross posted. I see now that probably won't be necessary. However I am not sure what you mean by CDMA. comp.catabases.ms-access |
![]() |
| Thread Tools | |
| Display Modes | |
| |