Microsoft Office Tutorials and References
In Depth Information
Moving Rows Between List Boxes
Having a Boolean field requires setting only a True to False or False to True.
All that is needed is to list only the False rows of the table in the From list box
and only the True rows in the To list box.
The query for the From list box:
SELECT tblMove.Sequence, tblMove.Field1, tblMove.Field2
FROM tblMove
WHERE tblMove.LeftRight=False;
The move itself is established by an Update query in the code. For moving one
row, use the behind > button:
Private Sub btnTo_Click()¶
' set the value of the LeftRight field to True for¶
' the selected row¶
If Me.lstFrom.ItemsSelected.Count > 0 Then¶
CurrentDb.Execute (UPDATE tblMove SET LeftRight=true WHERE
[Sequence]= & Me.lstFrom)¶
' make changes visible¶
Me.Refresh¶
Else¶
' No item selected¶
MsgBox “Please select ““From”” item”¶
End If¶
End Sub¶
The Boolean field is named LeftRight, and the main statement is the UPDATE
that sets the field to True for the selected row from the list box. We test for no
items being selected so that a warning is displayed.
Acs
Note The double quote is used twice to get the warning message to display. Also,
there is a me.refresh to make the changes visible.
The code for the Move All button is even easier. Simply update all fields to the
required value. Testing for no selection is not even necessary!
Private Sub btnAllTo_Click()¶
' switch all values of the LeftRight to True¶
CurrentDb.Execute (UPDATE tblMove SET LeftRight=True)¶
' make changes visible¶
Me.Refresh¶
End Sub¶
For other buttons, just switch names and True to False.
Search JabSto ::




Custom Search