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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dual list box form

Status
Not open for further replies.

bgv

Programmer
Sep 23, 2003
29
US
I want to build a form using two listboxes. The list box on the left would contain all of the records from a query of a lookup table, but without the records either previously selected or moved from the left list box to the right. The intent here is to use the left listbox as the master list and the right list box as the selcected records. Two buttons would be used to 'move' records from one list box to another.

|------------| |------------|
| abc | => | pqr |
| def | | stu |
| ghi | | vwx |
| jkl | <= | |
| mno | | |
|------------| |------------|

I have looked for examples of this type of a form using dual list boxes without success. How do I code this?
 
'Selected records' is a Value List, right?
And I hope 'Master' gets data from a table/query.

When you run the 'transfer' procedure:

For Each itm in Me.lstMaster.ItemsSelected
strSelected = strSelected & &quot;; &quot; & Me.lstMaster.ItemData(itm)
Next

Me.lstSelected.RowSource = Me.latSelected.RowSource & strSelected
Me.lstMaster.RowSource = &quot;Select Whatever From Wherever Where KeyField Not In (&quot; & Me.lstSelected & &quot;)&quot;

That (or something similar) should do the trick





[pipe]
Daniel Vlas
Systems Consultant

 
You'll need something like this to add a remove items to and from the listboxes. The assumption is the left listbox is the Master and the right is empty -

Private Sub AddToRight_Click()
Dim intCntr As Integer

For intCntr = List0.ListCount - 1 To 0 Step -1
If List0.Selected(intCntr) = True Then
List2.AddItem List0.ItemData(intCntr)
List0.RemoveItem intCntr
End If
Next intCntr
End Sub

Private Sub AddToLeft_Click()
Dim intCntr As Integer

For intCntr = List2.ListCount - 1 To 0 Step -1
If List2.Selected(intCntr) = True Then
List0.AddItem List2.ItemData(intCntr)
List2.RemoveItem intCntr
End If
Next intCntr

End Sub

Private Sub ClearLeft_Click()
Dim intCntr As Integer

For intCntr = List2.ListCount - 1 To 0 Step -1
List0.AddItem List2.ItemData(intCntr)
List2.RemoveItem intCntr
Next intCntr

End Sub
 
bgv
If you are interested in a ready made sample, go to and download accarch71.zip

It is an example of paired single select list boxes. Seems to be primarily what you were looking for. You can move a item from one list box to the other and back.

Tom
 
Daniel,

Actually, the code that I posted was tested in Access 2002 and it works.

The VBA for the later verisons of Access blur the line in the VBA.


Steve
 
Daniel,

I have to see if I can find the code for how this was handle in the ealier versions and post it.

Thanks for keeping me honest. ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top