Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to display 2 fields in 1 combobox?

Status
Not open for further replies.

awinnn

MIS
Jul 21, 2003
166
0
0
MY
Hi,
I want to display 2 fields in 1 combobox, just like Access. As for example, i want to display staff_no and staff_name in 1 combobox. Any idea?
 
I'm pretty sure that it cannot be done with VB's data bound combobox, but I'm willing to be proven wrong.
 

Nope, cannot be done, you are correct.

You could add two field values seperated by a tab or two.

Or, you could use a combo box and a list box.
See my last post in this thread222-334874
 
You can do it using the combo box in MS Forms 2.0 Object Library. Make a combo box, change its ColumnCount property to 2, and then add items in code using:

Code:
dim Index as Integer
ComboBox1.AddItem staff_no, Index 'puts the staff_no into column 0
ComboBox1.List(Index, 1) = staff_name 'puts the staff_name into column 1

You can access info using ComboBox1.Column(column_no)

You can put this in a loop and increment the index value if you're getting the data from a recordset.

One warning though, the FM20.dll is, I believe, not distributable (there's a couple threads on that around here), but I think it comes with MS office.

Hope that helps,
Brad.
 
Yes, that was also mentioned by me in a link in the thread I had mentioned above - there you would have found it.
 
Use a DataCombo control
If you make an SQL srtatement as the source of the combo box list that contains 2 fields, it will work except they you dont get the second column in straight columns unless you also pad them out with spaces an duse a non proportional font like courier
Example
SELECT ([First Name] & " " & [Last Name]) AS CombinedName FROM Customers ORDER BY [Last Name]
And put Combinedname into the list

Make the Bound Column the ID or whatever you want to use to find the record

To pad spaces to 20 characters for first column use Left(([First Name]& String(32,20)),20)
 
Hi all,
thanx for reply..:)
this is what i've got..

Do Until rs.EOF
cbobox.AddItem rs!staff_no & " " & rs!staff_name
rs.MoveNext
Loop

any idea? now i'm trying the above method..
thank you.
 
For starters:

cbobox.AddItem rs.Collect("staff_no") & vbTab & vbTab & rs.Collect("staff_name")

Then next step may be to limit the length of the text for the first column altogether:

cbobox.AddItem Left$(rs.Collect("staff_no"),10) & vbTab & vbTab & rs.Collect("staff_name")

and then use something like a tooltip, or a lable next to the combo, to display the reset of the text.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top