Home VBA ListView control - retrieve columns from selected item

# 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#
 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)