Multi Select

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Greetings...

I have a list box and the multi select is enabled in the properties. I have
buttons that move selected items from one list to another. How do I code it
to move the multiple selection? As of now, if there is a mutliple selection,
it only moves one of them.

Thanks,
Alfia
 
Greetings...

I have a list box and the multi select is enabled in the properties. I have
buttons that move selected items from one list to another. How do I code it
to move the multiple selection? As of now, if there is a mutliple selection,
it only moves one of them.

The Listbox exposes the ItemsSelected collection, which you can iterate to get at the included items:

Dim var As Variant

For each var in YourListbox.ItemsSelected
'/your code here to manipulate each item
'/refer to the items like this: YourListbox.Column(0, var)
Next var

See the online help topic for more info about the ItemsSelected collection:
http://msdn2.microsoft.com/en-us/library/aa201026(office.10).aspx



Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 
This is the code I am using to insert into a table, and show selection in
another list box:

CurrentDb.Execute "INSERT INTO tblMovement (EmpID, SupervisorID,
CurrentSupervisorID, CurrentADID, ADID, InsertDate, EffectiveDate,
CurrentUser) " & _
"VALUES (" & lstSelectEmp.Column(0) & ", " &
cboNewSupervisor.Column(0) & ", " & cboCurrentSupervisor.Column(0) & ", " &
cboCurrentSupervisor.Column(2) & ", " & cboNewSupervisor.Column(2) & ", " &
Format(txtInsertDate, "\#yyyy\-mm\-dd\#") & _
"," & Format(txtEffectiveDate, "\#yyyy\-mm\-dd\#") & ",
" & Chr$(34) & txtCurrentUser & Chr$(34) & ")"


How would I apply what you have said my code?
 
This is the code I am using to insert into a table, and show selection in
another list box:

CurrentDb.Execute "INSERT INTO tblMovement (EmpID, SupervisorID,
CurrentSupervisorID, CurrentADID, ADID, InsertDate, EffectiveDate,
CurrentUser) " & _
"VALUES (" & lstSelectEmp.Column(0) & ", " &
cboNewSupervisor.Column(0) & ", " & cboCurrentSupervisor.Column(0) & ", " &
cboCurrentSupervisor.Column(2) & ", " & cboNewSupervisor.Column(2) & ", " &
Format(txtInsertDate, "\#yyyy\-mm\-dd\#") & _
"," & Format(txtEffectiveDate, "\#yyyy\-mm\-dd\#") & ",
" & Chr$(34) & txtCurrentUser & Chr$(34) & ")"

I'm not sure what you're doing with your Insert statement; do you want to insert EACH selected item in lstSelectEmp into
tblMovement? If so, build the For - Next loop, and stick your INSERT statement into it:

Dim var as Variant

For each var in lstSelectEmp.ItemsSelected
CurrentDb.Execute "INSERT INTO tblMovement (EmpID, SupervisorID,
CurrentSupervisorID, CurrentADID, ADID, InsertDate, EffectiveDate,
CurrentUser) VALUES (" & lstSelectEmp.Column(0, var) & ", " &
cboNewSupervisor.Column(0) & ", " & cboCurrentSupervisor.Column(0) & ", " &
cboCurrentSupervisor.Column(2) & ", " & cboNewSupervisor.Column(2) & ", " &
Format(txtInsertDate, "\#yyyy\-mm\-dd\#") & "," & Format(txtEffectiveDate, "\#yyyy\-mm\-dd\#") & ", "
& Chr$(34) & txtCurrentUser & Chr$(34) & ")"

Next var

Note that I added the "var" to the lstSelectEmp.Column section ...

If that's not what you're trying to do, please explain further.

Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 
Thanks! I think this should do it. With this code, I am inserting all that
information into a table. The second list box is based off of what is in
that table. I have a list of available employees to assign to a new
supervisor. Sometimes the old supervisor is assigning multiple employees to
a new supervisor.
 
Back
Top