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

ListIndex = -1

Status
Not open for further replies.

DoubleL

Programmer
Dec 14, 2001
1
CA
I am getting information by way of a recordest from two database tables. On my form i have both a list box and combo box. The list box gets data from table1 (company name) and the combo box fills with data from table2 (employee name). When i click on a company name in the list box the combo box name changes so that the employee name and company name matches. The problem is when i go to save any changes, if i do not click on the combobox i get an error. The problem is that even though i click on the listbox the listindex of the combobox is always -1 unless i click on it everytime.

doubleL
 
I don't know what your code looks like but here's an example of what you could do. The example below assigns the ListIndex property of the List control to the ListIndex property of the Combo box control in the OnClick event of the List control. To access the data I use the List property to display the results in both selections.

Option Explicit

Private Sub Command1_Click()
MsgBox List1.List(List1.ListIndex) & " " & Combo1.List(Combo1.ListIndex)
End Sub

Private Sub Form_Load()
List1.AddItem "Item 1"
List1.AddItem "Item 2"
List1.AddItem "Item 3"
Combo1.AddItem "ITEM 1"
Combo1.AddItem "ITEM 2"
Combo1.AddItem "ITEM 3"
End Sub

Private Sub List1_Click()
Combo1.ListIndex = List1.ListIndex
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top