M
Memento
Hello guys,
I have a form with a listbox on it. This is a multiselect listbox. I want to
write the ID's of the items that i select in the listbox written in a field
from a table the listbox is bound to. Basically: i select two or three
hardware items in the listbox, and i want the primary keys of the hardware
items written in a coupled_hardware field in a users table. Specifically i'm
having trouble with the multiselect feature. I'm trying to use a For loop to
loop through multiple items, but it simply won't work...
Private Sub BtnClickAdd_DblClick()
Dim strHardwareItem As String
Dim addHardware As Boolean
Dim Cancel As Boolean
Dim sItem As Variant
Dim i As Integer
Cancel = True
addHardware = False
'code if multiple items are selected
strHardwareItem = lstHardware.Column(4) & ";" & " "
If lstHardware.ItemsSelected(i) > 0 Then
For i = 0 To lstHardware.ListCount - 1
For Each sItem In lstHardware.ItemsSelected
addHardware = True
Next sItem
Next i
Else
' code if only 1 item is selected
End If
'check if addhardware has a match, then bound strHardwareItem to field
Me![GekHardware]
If addHardware = True Then
Me![GekHardware] = strHardwareItem
Cancel = False
End If
lstAssignedHardware.Requery
End Sub
I have a form with a listbox on it. This is a multiselect listbox. I want to
write the ID's of the items that i select in the listbox written in a field
from a table the listbox is bound to. Basically: i select two or three
hardware items in the listbox, and i want the primary keys of the hardware
items written in a coupled_hardware field in a users table. Specifically i'm
having trouble with the multiselect feature. I'm trying to use a For loop to
loop through multiple items, but it simply won't work...
Private Sub BtnClickAdd_DblClick()
Dim strHardwareItem As String
Dim addHardware As Boolean
Dim Cancel As Boolean
Dim sItem As Variant
Dim i As Integer
Cancel = True
addHardware = False
'code if multiple items are selected
strHardwareItem = lstHardware.Column(4) & ";" & " "
If lstHardware.ItemsSelected(i) > 0 Then
For i = 0 To lstHardware.ListCount - 1
For Each sItem In lstHardware.ItemsSelected
addHardware = True
Next sItem
Next i
Else
' code if only 1 item is selected
End If
'check if addhardware has a match, then bound strHardwareItem to field
Me![GekHardware]
If addHardware = True Then
Me![GekHardware] = strHardwareItem
Cancel = False
End If
lstAssignedHardware.Requery
End Sub