Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List boxes and Requery... 1

Status
Not open for further replies.

Rjc8513

Technical User
Feb 12, 2001
140
US
I have a form containing two listboxes. In ListBox A are all sales units. ListBox A's data is supplied from the query, "ALL SALES UNITS".

I want to be able to select only the desired sales units in ListBox A and have them appear in ListBox B and then be placed in the table, "SELECTED SALES UNITS".

Thanks for the help.

Richard...
 
Add a Yes/No field to your tblSalesUnits, call it IsSelected. Set listA's row source criteria to IsSelected=False, listB's to IsSelected=True. When, say, the user double-clicks on listA, run the following code:
Code:
Private Sub listA_DblClick()

    CurrentDb.Execute("UPDATE tblSalesUnit SET IsSelected = Not [IsSelected] WHERE SalesUnitID = " & listA & ";")
    listA.Requery
    listB.Requery

End Sub
You can run it backwards from listB. Might need to put quotes around the listA value if it's not an ID but a string.
 
P.S. There's no need for a second table that way. You can just query against all sales units where IsSelected = True.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top