Hi Alex:
I was trying to have the user choose equipment from a list box and then
transfer this over with a command button to another list box to save data
entry and prvent typing errors. I tried to use a subroutine from somewhere I
had seen but the code actually moves items from one table to another instead
of just copying. Essentially what goes into the end listbox(es) will be used
for a record like a shipping list so there is a record. I tried to use a
sample that used a table called Source and one called Destination and make it
work for a table called EmployeeListing to start with then I was going to
have the other controls also copy and add to the final destination.
Below is the code
Private Sub btnDeselect_Click()
Dim rsDestination As DAO.Recordset
Dim theBug As String
If Me.lbDestination.ItemsSelected.Count = 0 Then
Beep
Exit Sub
End If
Set rsDestination = Me.lbDestination.Recordset
For Each itm In Me.lbDestination.ItemsSelected
On Error Resume Next
theBug = Me.lbDestination.ItemData(0)
rsDestination.FindFirst ("Description = '" &
Me.lbDestination.ItemData(itm) & "'")
rsDestination.Edit
rsDestination!InSelectedList = False
rsDestination.Update
Next itm
Me.lbSource.Requery
Me.lbDestination.Requery
End Sub
------------------------
Private Sub btnDeselectAll_Click()
Dim rsDestination As DAO.Recordset
Set rsDestination = Me.lbDestination.Recordset
rsDestination.MoveFirst
Do While Not rsDestination.EOF
rsDestination.Edit
rsDestination!InSelectedList = False
rsDestination.Update
rsDestination.MoveNext
Loop
Me.lbSource.Requery
Me.lbDestination.Requery
End Sub
------------------------
Private Sub btnSelect_Click()
Dim rsEmployeeListing As DAO.Recordset
Dim theBug As String
If Me.lbEmployeeListing.ItemsSelected.Count = 0 Then
Beep
Exit Sub
End If
Set rsSource = Me.lbEmployeeListing.Recordset
For Each itm In Me.lbEmployeeListing.ItemsSelected
theBug = Me.lbEmployeeListing.ItemData(0)
rsSource.FindFirst ("Description = '" &
Me.lbEmployeeListing.ItemData(itm) & "'")
rsSource.Edit
rsSource!InSelectedList = True
rsSource.Update
Next itm
Me.lbEmployeeListing.Requery
Me.lbDestination.Requery
End Sub
-----------------
Private Sub btnSelectAll_Click()
Dim rsEmployeeListing As DAO.Recordset
Set rsSource = Me.lbEmployeeListing1.Recordset
rsEmployeeListing.MoveFirst
Do While Not rsEmployeeListing.EOF
rsEmployeeListing.Edit
rsEmployeeListing!InSelectedList = True
rsEmployeeListing.Update
rsEmployeeListing.MoveNext
Loop
Me.lbEmployeeListing1.Requery
Me.lbDestination1.Requery
End Sub
-------------------
Private Sub Form_Open(Cancel As Integer)
Dim theSQL As String
theSQL = "SELECT Description, InSelectedList FROM BooleanList WHERE "
Me.lbEmployeeListing2.RowEmployeeListing = theSQL & "NOT InSelectedList"
Me.lbDestination2.RowEmployeeListing = theSQL & "InSelectedList"
End Sub