I was wondering if it was possible to bound 2 combo boxes to each other. the first combo box with a set of information. Based on what the user selects, the second combo box changes. this involves 2 tables.

table 1
ProductID
Descritption

table 2
Id
FK_ProductID
Category


example: the user selects Product in combo box 1
and the second combo box will fill product Categories based on "Product", such as "Outsourcing" or "Software Development"

Hi,

First Populate Combo1 with all the Available info, Write this in Form Load:

Dim RS As New ADODB.RecordSet
Dim sSQL As String
Combo1.Clear
sSQL="Select * From Table1 "
RS.Open sSQL,Conn
Do While Not RS.EOF
    Combo1.AddItem RS("Description") & ""
    Combo1.ItemData(Combo1.NewIndex) = Val(RS("ID") & "")
    RS.MoveNext
Loop
RS.Close

In LostFocus of Combo1, Write This Code to populate Corresponding Details:

Dim RS1 As New ADODB.RecordSet
Dim sSQL As String
Combo2.Clear
If Combo1.ListIndex>=0 Then
sSQL="Select * From Table2  Where " _
& " FK_ProductID=" &  Val(Combo1.ItemData(Combo1.ListIndex))
RS1.Open sSQL,Conn
Do While Not RS1.EOF
    Combo2.AddItem RS1("Category") & ""
    Combo2.ItemData(Combo2.NewIndex) = Val(RS1("ID") & "")
    RS1.MoveNext
Loop
RS1.Close

Regards
Veena

Hi,

First Populate Combo1 with all the Available info, Write this in Form Load:

Dim RS As New ADODB.RecordSet
Dim sSQL As String
Combo1.Clear
sSQL="Select * From Table1 "
RS.Open sSQL,Conn
Do While Not RS.EOF
    Combo1.AddItem RS("Description") & ""
    Combo1.ItemData(Combo1.NewIndex) = Val(RS("ID") & "")
    RS.MoveNext
Loop
RS.Close

In LostFocus of Combo1, Write This Code to populate Corresponding Details:

Dim RS1 As New ADODB.RecordSet
Dim sSQL As String
Combo2.Clear
If Combo1.ListIndex>=0 Then
sSQL="Select * From Table2  Where " _
& " FK_ProductID=" &  Val(Combo1.ItemData(Combo1.ListIndex))
RS1.Open sSQL,Conn
Do While Not RS1.EOF
    Combo2.AddItem RS1("Category") & ""
    Combo2.ItemData(Combo2.NewIndex) = Val(RS1("ID") & "")
    RS1.MoveNext
Loop
RS1.Close

Regards
Veena

Thanks Veena

Can you perhaps help me with the above using VB.Net

Regards
Sally

then you should have posted the question in .NET section of the forum not here.

Okay thanks,

the thread above "linking two combo boxes" is very good. Thank you. I used the concept. Please can someone help me to further develop it by getting the items that appears on the second combo box to appear on 7 other similar boxes on the form. That is, the 7 other sub combo boxes linking to the 1 Main. Thanks for your help. I'm new to the forum. emil_kan

i have taken two combo baxes in form by using vb.net how can i connect them both after conecting i want to show a image in anather page so how to design and how to code..

Please give me proper info vth example..

Sai Ganesh

This article has been dead for over six months. Start a new discussion instead.