View Full Version : Listbox


mbrown
06-28-2001, 05:35 AM
I have 2 listboxes. I want to muli-select from the 1st and have the choices show up in the second. I then need to push a button and have a form pop up to edit those choices.
Any help would be appreciated!!
Thanks,
Mike

Pat Hartman
06-28-2001, 06:17 AM
Here's an article that covers list and combo boxes in depth.
http://www.microsoft.com/AccessDev/Articles/Combo.HTM

Angello Pimental
06-28-2001, 09:03 AM
Ready for this?????

I believe I have what you are looking for......
The following code/instructions will set up two list boxes and a command button. The user will select multiple choices in list1, he/she will then press the command button "Transfer" and the names will appear in list2.
Then when the user selects the record he/she wants to see from list2, your edit form will pop open for that choice. He/she can then edit that record, close the edit form and then select the next record to edit in list2.

SO here is the code/instructions:

Create two listboxes, list1, and list2 and a cmd button

Properties list1:
mutliselect: simple
rowsource: Select table.choices From table;

Properties list2:
Rowsourcetype: Value list
Onclick property code:

Private Sub List2_Click()
On Error GoTo Err_List2_Click

Dim stDocName As String
Dim rst As Recordset, strCriteria As String
stDocName = "editform"


strCriteria = "[choices]=" & "'" & Me![List2] & "'"
DoCmd.OpenForm stDocName

Set rst = Forms!editform.RecordsetClone
rst.FindFirst strCriteria
Forms!editform.Bookmark = rst.Bookmark
Me!List2 = ""


Exit_List2_Click:
Exit Sub

Err_List2_Click:
MsgBox Err.Description
Resume Exit_List2_Click

End Sub

****Note Choices is the name of the field your user searchs the record by****

Command button:
Name :cmdcopyitem
Caption: whatever you please
On_Click property code:

Sub cmdCopyItem_Click()
CopySelected Me
End Sub

Function CopySelected(frm As Form) As Integer
Dim ctlSource As Control
Dim ctlDest As Control
Dim strItems As String
Dim intCurrentRow As Integer
Set ctlSource = frm!List1
Set ctlDest = frm!List2
For intCurrentRow = 0 To ctlSource.ListCount - 1
If ctlSource.Selected(intCurrentRow) Then
strItems = strItems & ctlSource.Column(0, intCurrentRow) & ";"
End If
Next intCurrentRow

' Reset destination control's RowSource property.
ctlDest.RowSource = ""
ctlDest.RowSource = strItems
End Function

And thats that... If you get into any problems just ask

HTH
Angelo

[This message has been edited by Angello Pimental (edited 06-28-2001).]

mbrown
06-28-2001, 10:34 AM
Thanks Pat and Angello.
Both responses helped.
Mike