J
John W. Vinson
This works fine if I select one or all, by clicking one by one.
I want that if nothing is selected then that means all are selected,
then the code runs for all records in the listbox.
Dim CashSQL As String
Dim varSelected As Variant
DoCmd.SetWarnings False
If Me.ListEmp.ItemsSelected.Count = 0 Then
CASHSQL = "UPDATE tblEmployees " & )
"SET tblEmployees.EmpCashedOut = -1"
Else
For Each varSelected In Me.ListEmp.ItemsSelected
CASHSQL = "UPDATE tblEmployees " & _
"SET tblEmployees.EmpCashedOut = -1 " & _
"WHERE tblEmployees.EmployeeId = " & _
Me.ListEmp.ItemData(varSelected)
Next
End If
DoCmd.RunSQL (CASHSQL)
This will update all employees in the entire table - you'll need to add some
criteria (those from the listbox's rowsource) if that's not what you want.
John W. Vinson [MVP]