Solved

Zero Value on Combo list

Posted on 2006-11-27
9
149 Views
Last Modified: 2010-04-30
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
0
Comment
Question by:teogos
  • 5
  • 4
9 Comments
 
LVL 18

Expert Comment

by:JR2003
ID: 18024230
If you want the text of the selected item you need:
cbocombo1.List(cbocombo1.ListIndex))
NOT
cbocombo1.List(cbocombo1.ListIndex - 1))

0
 

Author Comment

by:teogos
ID: 18024261
If do the cbocombo1.List(cbocombo1.ListIndex))
it shows the items one out sincronization
0
 
LVL 18

Expert Comment

by:JR2003
ID: 18024300
The items on a combo box have indexes going from 0 to n-1

What exactly is your code trying to do?
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:teogos
ID: 18024319
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

0
 

Author Comment

by:teogos
ID: 18024334
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
Ing_N0
Description

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
0
 
LVL 18

Expert Comment

by:JR2003
ID: 18026436
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.
0
 
LVL 18

Accepted Solution

by:
JR2003 earned 125 total points
ID: 18028195
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.
0
 

Author Comment

by:teogos
ID: 18106203
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
0
 
LVL 18

Expert Comment

by:JR2003
ID: 18107186
How about intead of:
cbocombo1.ListIndex = txting2.Text
put
cbocombo1.ListIndex = txting2.Text - 1

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question