Hi shylock,
As I believe I was the one that suggested this approach I would like to offer some more info. You actually loop through the ItemsSelected collection of the listbox(es)(if multiselect is enabled on the list box), not the temp table. Please have a look at the code included and adapt for your table;
Code:
Private Sub cmdAddAll_Click()
Dim varItem, lJoinID As Long, sSQL As String
For Each varItem In Me.lstAvailable.ItemsSelected
lJoinID = Me.lstAvailable.Column(0, varItem)
sSQL = "UPDATE tmpIncomingJobHoldUpdater SET [IsSelected]=True WHERE [IncomingJobJoinID] = " & lJoinID & ";" 'select the row
CurrentDb.Execute sSQL ', dbFailOnError
Next varItem
Me.lstAvailable.Requery
Me.lstSelected.Requery
End Sub
Private Sub cmdAddOne_Click()
Dim sSQL As String, lJobId As Long
lJobId = Me.lstAvailable.Column(0)
sSQL = "UPDATE tmpIncomingJobHoldUpdater SET [IsSelected]=True WHERE [IncomingJobJoinID] = " & lJobId & ";" 'select the row
CurrentDb.Execute sSQL, dbFailOnError
Me.lstAvailable.Requery
Me.lstSelected.Requery
End Sub
Private Sub cmdRemoveOne_Click()
Dim sSQL As String, lJobId As Long
lJobId = Me.lstSelected.Column(0)
sSQL = "UPDATE tmpIncomingJobHoldUpdater SET [IsSelected]=False WHERE [IncomingJobJoinID] = " & lJobId & ";" 'deselect the row
CurrentDb.Execute sSQL, dbFailOnError
Me.lstAvailable.Requery
Me.lstSelected.Requery
End Sub
Private Sub cmdRemoveAll_Click()
Dim varItem, lJoinID As Long, sSQL As String
For Each varItem In Me.lstSelected.ItemsSelected
lJoinID = Me.lstSelected.Column(0, varItem)
sSQL = "UPDATE tmpIncomingJobHoldUpdater SET [IsSelected]=False WHERE [IncomingJobJoinID] = " & lJoinID & ";" 'select the row
CurrentDb.Execute sSQL ', dbFailOnError
Next varItem
Me.lstAvailable.Requery
Me.lstSelected.Requery
End Sub
Private Sub lstAvailable_DblClick(Cancel As Integer)
Call cmdAddOne_Click
End Sub
Private Sub lstSelected_DblClick(Cancel As Integer)
Call cmdRemoveOne_Click
End Sub
Private Sub cmdCancel_Click()
DoCmd.Close
End Sub
Hope it helps.
Cheers,
Vlad