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

COMBOBOX

Status
Not open for further replies.

lode

Programmer
Nov 8, 2001
208
BE
Hi,

I placed a combobox an a form.

The combo is displaying a text, with that text comes a value

Let's say Combotext Code
--------- -----
Product 1 RO27
Product 2 RO25
Product 3 RO28
etc.

So, I can get the text in my Combobox but I also need the values.
When the User picks Product 3, I need the value RO28.

Thanks


 
Hi Lode,
Assuming that "Product1 RO27" is one line of text and
not knowing how many spaces delimit the product from the code I suggest trying the Right() statement.
e.g

Private Sub Combo1_Click()
Str = Trim(Right(Combo1.Text, 5))
Debug.Print Str
End Sub

If you know how many spaces you also use the Split() statement.
Dim arr() as String
arr() = Split(Combo1.Text," ")' " " equal to # of spaces
Debug.Print arr(1)
Jon
 
Hi,

Thanks for your reply.

The values have to come from two fields of a table.
But i can only add one field to the combobox.
 
Hi Lode,

How are the values added to the ComboBox? Can you post a little bit of code? Maybe there is a way to reference the second value in an array based on the ListIndex property

Jon
 
hi!
I think i have the solution for ur probelm.
u can do one thing.
Declare an array of string type .
Redim the array when u open the recordet from the the values are to be filled in the combobox.
Declare a variable of string type.
Try to use following code.

dim v_ArrTrTypCode() as string
dim f_TrTypeCd as string
Public Sub FillTrType()
Dim v_RsTrType As New ADODB.Recordset
Dim v_StrTblName As String
Dim v_IntIndex As Integer
v_StrTblName = g_TrTypeMaster
With v_RsTrType
.ActiveConnection = g_cn
.CursorLocation = adUseClient
.CursorType = adOpenForwardOnly
.LockType = adLockOptimistic
.Source = &quot;select * from &quot; & v_StrTblName & &quot; where tt_TypeId like 'G%' and tt_typeid<>'G$'&quot;
.Open
v_IntIndex = 1
If Not v_RsTrType.RecordCount < 1 Then
ReDim v_ArrTrTypCode(1 To v_RsTrType.RecordCount)
End If
Do While Not (v_RsTrType.EOF Or v_RsTrType.BOF)
v_ArrTrTypCode(v_IntIndex) = v_RsTrType.Fields(&quot;tt_TypeId&quot;).Value
cboTransType.AddItem v_RsTrType.Fields(&quot;tt_Desc&quot;).Value
v_RsTrType.MoveNext
v_IntIndex = v_IntIndex + 1
If v_IntIndex > v_RsTrType.RecordCount Then Exit Do
Loop
.Close
End Sub
Private Sub cboTransType_Click()
If Not cboTransType.ListIndex < 0 Then
f_TrTypeCd = v_ArrTrTypCode(cboTransType.ListIndex + 1)
End If
End Sub

 
hi!
I think i have the solution for ur probelm.
u can do one thing.
Declare an array of string type .
Redim the array when u open the recordet from the the values are to be filled in the combobox.
Declare a variable of string type.
Try to use following code.

dim v_ArrTrTypCode() as string
dim f_TrTypeCd as string
Public Sub FillTrType()
Dim v_RsTrType As New ADODB.Recordset
Dim v_StrTblName As String
Dim v_IntIndex As Integer
v_StrTblName = g_TrTypeMaster
With v_RsTrType
.ActiveConnection = g_cn
.CursorLocation = adUseClient
.CursorType = adOpenForwardOnly
.LockType = adLockOptimistic
.Source = &quot;select * from &quot; & v_StrTblName & &quot; where tt_TypeId like 'G%' and tt_typeid<>'G$'&quot;
.Open
v_IntIndex = 1
If Not v_RsTrType.RecordCount < 1 Then
ReDim v_ArrTrTypCode(1 To v_RsTrType.RecordCount)
End If
Do While Not (v_RsTrType.EOF Or v_RsTrType.BOF)
v_ArrTrTypCode(v_IntIndex) = v_RsTrType.Fields(&quot;tt_TypeId&quot;).Value
cboTransType.AddItem v_RsTrType.Fields(&quot;tt_Desc&quot;).Value
v_RsTrType.MoveNext
v_IntIndex = v_IntIndex + 1
If v_IntIndex > v_RsTrType.RecordCount Then Exit Do
Loop
.Close
End Sub
Private Sub cboTransType_Click()
If Not cboTransType.ListIndex < 0 Then
f_TrTypeCd = v_ArrTrTypCode(cboTransType.ListIndex + 1)
End If
End Sub

regards

 
Whoa there! Simply use the Additem and ItemData properties then whenever the user selects you retrieve itemdata - naturally the text below can be replace with a recordset field name/number

To Add Data:
Combo.AddItem (&quot;Product 3&quot;) - 'text to be displayed
Combo.ItemData(Combo.NewIndex)= &quot;RO28&quot; 'Data to be retrieved

To Retrieve User selection
Combo.ItemData(Combo.ListIndex)


I have my own procedure for doing this if you want a look. reply to this post
 
Hi, thanks all for your responses.
I can go on now !!!!
Thanks again.

Lode.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top