|  | Combobox to Listbox |  | |
| | | GoCoogs |  |
| Posted: Mon Sep 22, 2008 7:02 pm Post subject: Combobox to Listbox |  |
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 |
| |
| | | Tom Wickerath |  |
| Posted: Mon Sep 22, 2008 7:02 pm Post subject: RE: Combobox to Listbox |  |
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 MVP LINK LINK __________________________________________
"GoCoogs" wrote:
| Quote: | 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 |
|
| |
| | | fredg |  |
| Posted: Mon Sep 22, 2008 7:02 pm Post subject: Re: Combobox to Listbox |  |
| |  | |
On Mon, 22 Sep 2008 12:02:05 -0700 (PDT), GoCoogs wrote:
| Quote: | 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).
-- Fred Please respond only to this newsgroup. I do not reply to personal e-mail |
| |
| | | Tom Wickerath |  |
| Posted: Mon Sep 22, 2008 8:18 pm Post subject: Re: Combobox to Listbox |  |
Ah, I didn't notice the spelling difference (Coogs vs. Cougs). I thought you were a WSU (Washington State University--Pullman, WA.) fan. I'm more of a Huskie--University of Washington (Seattle) (aka Dawgs) fan. As you might guess, there is quite a rivalry.
Tom Wickerath Microsoft Access MVP LINK LINK __________________________________________
"GoCoogs" wrote:
| Quote: | 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. |
|
| |
| | | GoCoogs |  |
| Posted: Mon Sep 22, 2008 8:54 pm Post subject: Re: Combobox to Listbox |  |
| |  | |
On Sep 22, 2:22 pm, Tom Wickerath <AOS168b AT comcast DOT net> wrote:
| Quote: | 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 LINK __________________________________________
"GoCoogs" wrote: 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- Hide quoted text -
- 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. |
| |
|
|