From: M Skabialka on
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

From: Rich P on
To retrieve the selected item from a listbox you can do this:

Private Sub List0_Click()
Dim i As Integer
i = List0.ListIndex
Debug.Print List0.Column(1, i + 1)
End Sub

Note: the ListIndex property begins counting at 0 and the column
property -- row parameter -- begins at 1 so you have to add 1 to the
listIndex value to retrieve the data from the correct row of the
Listbox. The parameters for the listbox are column#, row#.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
From: Douglas J. Steele on
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(a)NOSPAMdrc.com> wrote in message
news:huo91h$fje$1(a)speranza.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


From: M Skabialka on
Solved with:

Dim rst As dao.Recordset

Set rst = Me.RecordsetClone

rst.FindFirst "InventoryID = " & Me.lstInventory.Column(1)
Me.Bookmark = rst.Bookmark

rst.Close
Set rst = Nothing

I think I was trying to make something easy into something complicated.
Mich

"Douglas J. Steele" <NOSPAM_djsteele(a)NOSPAM_gmail.com> wrote in message
news:huoc2d$m6q$1(a)news.eternal-september.org...
> 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(a)NOSPAMdrc.com> wrote in message
> news:huo91h$fje$1(a)speranza.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
>
>

From: David W. Fenton on
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/