Combobox to Listbox

G

GoCoogs

I have a combobox that contains a list of all employees and an empty
listbox. I want the user to be able to add employees to the listbox by
selecting them in the combo box and pressing a button. I have found a
work around the get the employee's name but not their employee ID,
which is a hidden column in the combo box. Is there a simple way to
copy the selected combo box item to the listbox?

Private Sub btnAdd_Click()
If Me.cboStaff.Value = 0 Then
MsgBox ("Please select a staff member")
Else
Me.cboStaff.SetFocus
strcbotext = Me.cboStaff.Text
Me.lstStaff.AddItem (strcbotext)
End If
End Sub


Thanks,
Blake
 
F

fredg

I have a combobox that contains a list of all employees and an empty
listbox. I want the user to be able to add employees to the listbox by
selecting them in the combo box and pressing a button. I have found a
work around the get the employee's name but not their employee ID,
which is a hidden column in the combo box. Is there a simple way to
copy the selected combo box item to the listbox?

Private Sub btnAdd_Click()
If Me.cboStaff.Value = 0 Then
MsgBox ("Please select a staff member")
Else
Me.cboStaff.SetFocus
strcbotext = Me.cboStaff.Text
Me.lstStaff.AddItem (strcbotext)
End If
End Sub

Thanks,
Blake

Blake,

Here is one method.
It will add both the EmployeeID and the EmployeeName to the list box.

Assuming the first Combo Box column (the bound column, hidden) is the
EmployeeID column, and the EmployeeName column is the 2nd column:

Leave the list box Rowsource property blank.
Set the list box RowSourceType property to Value List.

Code the Combo box AfterUpdate event (all on one line):

Me.lstBoxName.RowSource = Me.lstBoxName.RowSource & Me.ComboName & ","
& Me.ComboName.Column(1) & ","

Set the lstBoxName Column Count property to 2.
Set the Column Widths property to:
0.5";1.5"
if you wish to show both the ID and the Name.
If you only wish to show the name column, then set the Column Widths
property to
0";1.5"

Set the Bound Column to 1 (the EmployeeID column).
 
G

GoCoogs

Try Me.cboStaff.Column(0), if you are trying to get the first field in the
row source. When using VBA code, the columns are zero-based.

Dawgs eat Coogs for breakfast!

Tom Wickerath
Microsoft Access MVPhttp://www.accessmvp.com/TWickerath/http://www.access..qbuilt.com/html/expert_contributors.html
__________________________________________







- Show quoted text -

Thanks for the help Tom. I was in college (University of Houston) when
I created this account for Google groups. I have not figured out how
to change my name from appearing as GoCoogs. Whenever I post questions
now I am afraid people think I am trying to get them to do my homework
for me.

Anyway you would need a pretty big dog to eat a cougar.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top