[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Retrieve value from second column of selected item in a MS Access listview

Posted on 2011-04-28
14
Medium Priority
?
1,177 Views
Last Modified: 2013-04-25

From the dbl click event of a listview I retrieve the value from first column of the selected item like this: intProductId = Forms!frmInventory.lstListView1.SelectedItem.Text

This works fine, but how can i retrieve the value from the second column?
Appreciate any suggestions.
0
Comment
Question by:hallpett
  • 8
  • 5
14 Comments
 
LVL 15

Expert Comment

by:Simon Ball
ID: 35481417
not sure if there is a more direct way, I always have to iterate the items selected collection to find the relevant items,

then use column(x,y) to get to the 2nd column.

i've got some code i'll dig out a sample
0
 
LVL 6

Expert Comment

by:TinTombStone
ID: 35481420
intProductID = Forms!frmInventory.lstView1.Value

will give you the value of the bound column

for other columns (column 1 = 0)

strProductName = Forms!frmInventory.lstView1.Column(1)
dblProductPrice = Forms!frmInventory.lstView1.Column(2)
0
 
LVL 15

Expert Comment

by:Simon Ball
ID: 35481424
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

Open in new window


0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:hallpett
ID: 35481742
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.lstView1.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?
0
 
LVL 15

Expert Comment

by:Simon Ball
ID: 35481804
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
0
 

Author Comment

by:hallpett
ID: 35481901
Yes I changed to lstListView1. Could my reference be a problem (see image)?
2011-04-28-104018.jpg
0
 
LVL 15

Expert Comment

by:Simon Ball
ID: 35481983
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
0
 
LVL 15

Expert Comment

by:Simon Ball
ID: 35482041
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...
0
 
LVL 15

Expert Comment

by:Simon Ball
ID: 35482080
i cannot even get it to work to pick up the main selection

Forms!Form1!ListView0.SelectedItems.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...
0
 

Author Comment

by:hallpett
ID: 35482123
I still get error: "Object doesn't support this property or method".

intProductId = Forms!frmInventory.lstListView1.SelectedItem.Text
strProductName=Forms!frmInventory.lstListView1.SelectedItems(0).SubItems(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!  
0
 
LVL 15

Accepted Solution

by:
Simon Ball earned 1500 total points
ID: 35482201
yeah, thats what i was going to suggest next... but i cannot even get that first line working in my code.
0
 

Author Closing Comment

by:hallpett
ID: 35752246
We did not find the solution I was looking for, but problem can be solved with the proposed workaround.
0
 
LVL 15

Expert Comment

by:Simon Ball
ID: 35752488
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.
0
 

Author Comment

by:hallpett
ID: 39110997
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.lstListView1.SelectedItem.SubItems(2)
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question