Looking up values in a list box.

S

scadav

I have a unbound combo box that is getting its value from a two column
table. The combo box has two columns and is bound to the first one,
but the column widths are set such that the user can not see the
numeric value associated with the text.

I have created a button that allows a user to choose a value from the
combo box and add the items to a list box (giving the user the ability
to select multiple values). The code is below:

Me.listbox_MultipleEmployementStatus.AddItem Me.cb_Status


When I do this, the value that gets sent over to the list box is the
numeric identifier, which is obviously going to confuse the user. How
do I push both the ID and the value over to the list box, so the user
see the text, but I am able to use the numeric identifier
appropriately.

Thanks
 
D

Damon Heron

Instead of a combobox to select from, I suggest a listbox set to multiple
selections. Then use the following subroutine, called by a button click, to
move the selected items to the destination listbox:

Public Sub CopySelected() ' Move selected list items to destination
listboxes.
Dim ctlSource As control
Dim ctlDest As control
Dim strItems As String
Dim intCurrentRow As Integer
dim ct as integer
ct = 0
Set ctlSource = Me!lstFrom 'name of your listboxes
Set ctlDest = Me!lstTo 'name of your listboxes
For intCurrentRow = 0 To ctlSource.ListCount - 1
If ctlSource.Selected(intCurrentRow) Then
strItems = strItems & ctlSource.Column(0, intCurrentRow) & ";" & _
ctlSource.Column(1, intCurrentRow) & ";"
ct = ct + 1
End If
Next intCurrentRow

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

Set ctlSource = Nothing
Set ctlDest = Nothing

End Sub
 

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