hallpett
asked on
Retrieve value from second column of selected item in a MS Access listview
From the dbl click event of a listview I retrieve the value from first column of the selected item like this: intProductId = Forms!frmInventory.lstList
This works fine, but how can i retrieve the value from the second column?
Appreciate any suggestions.
intProductID = Forms!frmInventory.lstView 1.Value
will give you the value of the bound column
for other columns (column 1 = 0)
strProductName = Forms!frmInventory.lstView 1.Column(1 )
dblProductPrice = Forms!frmInventory.lstView 1.Column(2 )
will give you the value of the bound column
for other columns (column 1 = 0)
strProductName = Forms!frmInventory.lstView
dblProductPrice = Forms!frmInventory.lstView
Dim x As Integer
For x = 0 To List7.ListCount
If List7.Selected(x) Then
MsgBox List7.Column(1, x) & " - " & List7.Column(2, x)
end if
next
ASKER
Get an error when I try to implement both solutions:
"Object doesn't support this property or method".
Would be best if i could get TinTombStones solutions to work: "strProductName = Forms!frmInventory.lstView 1.Column(1 )". I'm a novice on this field but shouldn't we somehow say that it's the selected item we want to retrieve value from?
"Object doesn't support this property or method".
Would be best if i could get TinTombStones solutions to work: "strProductName = Forms!frmInventory.lstView
did you change my list7 to lstView1?
Dim x As Integer
For x = 0 To lstView1.ListCount
If lstView1.Selected(x) Then
MsgBox lstView1.Column(1, x) & " - " & lstView1.Column(2, x)
end if
next
Dim x As Integer
For x = 0 To lstView1.ListCount
If lstView1.Selected(x) Then
MsgBox lstView1.Column(1, x) & " - " & lstView1.Column(2, x)
end if
next
ASKER
Yes I changed to lstListView1. Could my reference be a problem (see image)?
2011-04-28-104018.jpg
2011-04-28-104018.jpg
aaah, sorry, I had wrongly assumed you were using a default ms access list control.
not used the activex listview control.
will do some research and mock up a test
not used the activex listview control.
will do some research and mock up a test
ListView0.SelectedItems(0) .SubItems( 1).Text should work according to vb forums:
http://www.vbforums.com/showthread.php?t=573387
but its not working in my mockup...
the listview0 does not have a selected items collection...
http://www.vbforums.com/showthread.php?t=573387
but its not working in my mockup...
the listview0 does not have a selected items collection...
i cannot even get it to work to pick up the main selection
Forms!Form1!ListView0.Sele ctedItems. Text gives me an error.
i tried amending the multiselect, hide selection and fullrowselect options too, to no avail.
i think we need someone who knows how to use this control successfully to help...
Forms!Form1!ListView0.Sele
i tried amending the multiselect, hide selection and fullrowselect options too, to no avail.
i think we need someone who knows how to use this control successfully to help...
ASKER
I still get error: "Object doesn't support this property or method".
intProductId = Forms!frmInventory.lstList View1.Sele ctedItem.T ext
strProductName=Forms!frmIn ventory.ls tListView1 .SelectedI tems(0).Su bItems(1). Text
The first of this two lines of code workes and i get the ProductId, but second line gives error. Since I have the ProductId I think I just have to write me a small function to get the ProductName directly from the table instead. Thanks for the effort!
intProductId = Forms!frmInventory.lstList
strProductName=Forms!frmIn
The first of this two lines of code workes and i get the ProductId, but second line gives error. Since I have the ProductId I think I just have to write me a small function to get the ProductName directly from the table instead. Thanks for the effort!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
We did not find the solution I was looking for, but problem can be solved with the proposed workaround.
nice one.
i thnik maybe its just not possible with that control.
do you have to use that list control? if you use the ordinary access one its much easier.
i thnik maybe its just not possible with that control.
do you have to use that list control? if you use the ordinary access one its much easier.
ASKER
This is the solution.
If you for instance want to get the value from selected item column 3 you can use this syntaks:
intProductId = Forms!frmInventory.lstList View1.Sele ctedItem.S ubItems(2)
If you for instance want to get the value from selected item column 3 you can use this syntaks:
intProductId = Forms!frmInventory.lstList
then use column(x,y) to get to the 2nd column.
i've got some code i'll dig out a sample