Home VBA ListView control - retrieve columns from selected item
Reply: 2

VBA ListView control - retrieve columns from selected item

dfranczyk
1#
dfranczyk Published in 2018-01-12 21:52:55Z

I have a ListView object within my Microsoft Access database that is set to Report View. When a user selects a row from this list, I want to be able to open a secondary form and populate based on the selected values. I am running into trouble with the proper syntax for capturing the column values I need. I have searched high and low looking for information on this, however I have not been able to find anything that fits my particular criteria.

Here is the code in question:

Private Sub ListView1_ItemClick(ByVal Item As Object)

  Dim FormID, FilingID, RowIndex As Integer
  Dim FilingName As String

  RowIndex = Item.Index

  FormID = Item.SubItems(0)
  FilingID = Item.SubItems(1)
  FilingName = Item.SubItems(2)

  If MsgBox("Do you want to open up filing " & FilingName & "?", vbYesNo, "Confirmation") = vbYes Then
     DoCmd.OpenForm "frmFiling", acNormal, , , , , "FormID=" & FormID & ";FilingID=" & FilingID
  End If

End Sub

This code keeps throwing an exception on the line FormID = Item.SubItems(0) stating that it is an invalid property value.

Does anybody know what I am doing wrong here, or have a workaround that accomplishes what I am trying to do?

itsLex
2#
itsLex Reply to 2018-01-13 08:50:59Z

In your line FormID = Item.SubItems(0) where you declared FormID as a variant, you are assigning an object to it, so VBA expects SET FormID = Item.SubItems(0).

However what you want is probably FormID = CInt(Item.SubItems(0).Text)

dfranczyk
3#
dfranczyk Reply to 2018-01-15 20:42:48Z

I changed the event from ItemClick to Click, and used ListView1.SelectedItem.ListSubItems(1).Text to extract the column value.

Thanks everyone for your comments.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.311712 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO