Hi all -
I have (hopefully) a simple problem that I need help with. I have a simple form that has a multi-select list box that is populated by another table. The list box shows one value (the 3rd column), but the table has 3 columns (the first two are not shown. When the user clicks the button, I want to populate a new record with each of the three variables. The number of grantees selected shows the right number, but I seem to be having trouble moving through the selected records. Here is my code so far, but this only shows the values of the last selected item over and over. I seem to be having trouble looping though the selected items.
Private Sub Command4_Click()
If Me.List2.ItemsSelected.Count = 0 Then
MsgBox "No grantee has been selected - please try again"
Else
MsgBox "Number of grantees selected: " & Me.List2.ItemsSelected.Count
Dim x As Variant
For Each x In Me.List2.ItemsSelected
MsgBox Me.List2.Column(0)
MsgBox Me.List2.Column(1)
MsgBox Me.List2.Column(2)
Next
End If
End Sub
Any help would be much appreciated!
I have (hopefully) a simple problem that I need help with. I have a simple form that has a multi-select list box that is populated by another table. The list box shows one value (the 3rd column), but the table has 3 columns (the first two are not shown. When the user clicks the button, I want to populate a new record with each of the three variables. The number of grantees selected shows the right number, but I seem to be having trouble moving through the selected records. Here is my code so far, but this only shows the values of the last selected item over and over. I seem to be having trouble looping though the selected items.
Private Sub Command4_Click()
If Me.List2.ItemsSelected.Count = 0 Then
MsgBox "No grantee has been selected - please try again"
Else
MsgBox "Number of grantees selected: " & Me.List2.ItemsSelected.Count
Dim x As Variant
For Each x In Me.List2.ItemsSelected
MsgBox Me.List2.Column(0)
MsgBox Me.List2.Column(1)
MsgBox Me.List2.Column(2)
Next
End If
End Sub
Any help would be much appreciated!