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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Doubts about Combo Box

Status
Not open for further replies.

Rhadamanthys

Programmer
Sep 16, 2003
3
0
0
BR
Hi there,

This is my doubt. I have this application developed in Access that has a combo box that works like this:

When the user press the arrow to open the combo box items it brings two iformation, lets say, a client code and a client name. The person can pick the client and when he/she does it, only the client code is selected in the combo box text.

In VB I dont figure out how to use the combo box to list more than one information per record !
I´d like to have something like this in the items of my combo box:

12 - John Doe
23 - Sarah Doe
45 - Peter Doe

where 12 is the client code e the name is the client identification and when the person picks one item, only the client code is selected in the combo box text ! Is there any way of doing that without using concatenation of the information?

Any idea?

Thanx
 
>there's Column(x,y) property

Not in VB's Combobox control there isn't. You'd need to add Microsoft Forms 2.0 to your project as a component to get this.
 
I guess I could have been clearer in my post. All the properties that hellbound66 refers to are properties of the Forms 2.0 Combobox (the one included with VBA), not of the VB6 Combobox
 
A little long winded but try this example out. I think you will get the idea. It will display in the way as you indicated above.

To use this example, start a new form. Place the standard VB combo box in the middle of the form and leave it named 'Combo1'. Now copy and paste the code below into the new form directly under the 'Option Explicit' found in the declarations section of the form (REMOVE the Form_Load event first). Fire it up.

The code you need to provide this effect is actually quite small.

' *********** Code Start *************

Private Sub Combo1_Click()

Dim RecID As Integer
Dim RecName As String

RecID = Val(Left$(Me.Combo1.Text, InStr(1, Me.Combo1, "--")))
RecName = Trim(Right$(Me.Combo1, (Len(Me.Combo1) - InStr(1, Me.Combo1, "--") - 8)))
Me.Combo1 = RecName
MsgBox "You selected Record ID number: " & RecID & vbCrLf & "which is related to the name: " & RecName

End Sub

Private Sub Form_Load()

Dim RecID() As Integer
Dim RecName() As String
Dim x As Long, i As Integer

x = 0
For i = 1 To 1200
ReDim Preserve RecID(x)
ReDim Preserve RecName(x)
RecID(x) = i
RecName(x) = "Sample Name" & CStr(x)
x = x + 1
Next

For i = 0 To UBound(RecID)
x = Len(CStr(RecID(i))) + Len(CStr(RecID(i)))
Me.Combo1.AddItem CStr(RecID(i)) & Space(12 - x) & "--" & Space(8) & RecName(i)
Next
Erase RecID
Erase RecName

End Sub


'********** CODE END ************


=======================
Life is like a box of BASIC
 
Not sure if CyberLynx helped you or not, but I needed a similar thing on a database I created and I managaed it without using code...

I have a combo box which a user can choose a personal trainer from. The surname and firstname were different fields, so I wanted to show them both, but only record the trainer's id (which is not shown).

The combo box properties are as follows:

Row Source type: Table/Query
Row Source: SELECT Trainers.TrainerID, Trainers.Firstname, Trainers.Surname FROM Trainers ORDER BY Trainers.Firstname;
Column Count: 3
Column Heads: No
Column Widths: 0cm;2cm;2cm
Bound Column: 1
Limit to List: Yes

Hope this helps!

moon_raevan@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top