Zero Value on Combo list

I have the following code

cbocombo1.ListIndex = txtIng1.Text
Dim ComboValue1() As String
ComboValue1 = Split(cbocombo1.List(cbocombo1.ListIndex - 1))
lbling1.Caption = Trim(ComboValue1(2))

it works but when an item on the combolist has a value of Zero then then it tells me subscript out of range,

is there any way that it the items on the combolist have a value of zero just ignore the statement
Who is Participating?
JR2003Connect With a Mentor Commented:
Just add a label to your form and try this in the cboCombo1_Click event:

Label1.Caption = cboCombo1.List(cboCombo1.ListIndex))

You will see that the label displays the selected combo item.
If you want the text of the selected item you need:
cbocombo1.List(cbocombo1.ListIndex - 1))

teogosAuthor Commented:
If do the cbocombo1.List(cbocombo1.ListIndex))
it shows the items one out sincronization
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

The items on a combo box have indexes going from 0 to n-1

What exactly is your code trying to do?
teogosAuthor Commented:
OK, I am trying to display the items from and access table
Field1  has a number 1 to 300
Field2 has a description to each of the 1 to 300 of field1

when I select item 1 ffrom field1, then I want to display the corresponding description which is on field2

teogosAuthor Commented:
Let me explain this a little better, Two tables from access database

Table 1 is called Final
Table 2 is ING

Final contains a field called Ing_N0, which is a number, now on the ING table
the fields are

When the user selects a Ing_N0 from the Final table I want this number to look on the ING table and display the description based on the ING_N0 selected
Are they standard comboboxes?
Do you do to the database after the user has selected a Ing_N0 from the Final table combo or are the values already in the other combo?
It might help if you pasted in some more code.
teogosAuthor Commented:
Sorry took so long to come back, but I still have problems with this
I know the listindex begins at zero , but the table does not have am item zero

here is what I have that I can not figure out

Private Sub txting2_Change()
cbocombo1.ListIndex = txting2.Text
Dim ComboValue2() As String
ComboValue2 = Split(cbocombo1.List(cbocombo1.ListIndex))
lbling2.Caption = Trim(ComboValue2(2))
lbling2b.Caption = Trim(ComboValue2(4))
lbling2c.Caption = Trim(ComboValue2(6))
lbl2d.Caption = Trim(ComboValue2(8))
lbl2f.Caption = Trim(ComboValue2(10))
End Sub

txting2 is always out of sinc with the other fields
How about intead of:
cbocombo1.ListIndex = txting2.Text
cbocombo1.ListIndex = txting2.Text - 1

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.