I have a listbox that uses data from a query. The query contains the names of people and their ID. I have the listbox only displaying the name. When I select an item in the list box, I want to use the AfterUpdate() in VBA to change the current recordset to the ID of the person just selected. Users are not able to select more than one item in the listbox
Here is some code which I got from one of the example databases on this forum
Private Sub List26_AfterUpdate()
Dim Cursisten As String
Dim ctl As Control
Dim Itm As Variant
Set ctl = Me.List2
For Each Itm In ctl.ItemsSelected
If Len(Cursisten) = 0 Then
Cursisten = ctl.ItemData(Itm)
Else
Cursisten = Cursisten & "," & ctl.ItemData(Itm)
End If
Next Itm
Me.txtCursisten = Cursisten
End Sub
Here is some code which I got from one of the example databases on this forum
Private Sub List26_AfterUpdate()
Dim Cursisten As String
Dim ctl As Control
Dim Itm As Variant
Set ctl = Me.List2
For Each Itm In ctl.ItemsSelected
If Len(Cursisten) = 0 Then
Cursisten = ctl.ItemData(Itm)
Else
Cursisten = Cursisten & "," & ctl.ItemData(Itm)
End If
Next Itm
Me.txtCursisten = Cursisten
End Sub