I have made some(10) combo boxes in my project!!! i need to make them depend the one on the other... i mean if the first combobox is a car brand (e.g Ferrari) then the second combobox must only contain ferrari models! is there a way to hide the rest selections in a combo box when the ferrari is chosen so that only ferrari models are shown in the second?

for that u need to add the itemsdynamically to the combo at runtime.

for that u need to add the itemsdynamically to the combo at runtime.

is there a tutorial explaining this?

I don't have any tutorial to explain all that.But i would suggest you to store all the data in database and select from there using SQL query and fill the remaining combo dynamically at runtime.

ok thnx

is there a code that to the computer means the following?

if combo1 = ferrari then disable carrera in combo2

Is this what you want?

Private Sub Combo1_Click()
If Combo1.ListIndex = 0 Then
Combo2.Text = "No data"
MsgBox "Please select a car manufacturer."
ElseIf Combo1.ListIndex = 1 Then
Combo2.Clear
Combo2.AddItem "Holden 1"
Combo2.AddItem "Holden 2"
Combo2.Text = Combo2.List(0)
ElseIf Combo1.ListIndex = 2 Then
Combo2.Clear
Combo2.AddItem "Ford 3"
Combo2.AddItem "Ford 4"
Combo2.Text = Combo2.List(0)
End If
End Sub

Private Sub Form_Load()
Combo1.AddItem "No data"
Combo1.AddItem "Holden"
Combo1.AddItem "Ford"
Combo1.Text = Combo1.List(0)
Combo2.AddItem "No data"
Combo2.Text = Combo2.List(0)
End Sub

think so...
thnx

Instead of going for all these hardcoding ,its always better to go for database connetion and fill the combo from database tables at runtime as per user selection.

if i only knew how to do it..

suppose in a table u store all the company names and in another table all there products.

now in the form load read all the company name name from table1. whwn u change the selection in the combo ,u need to execute the select command in database and select only the related products of the selected company only.

In this case you dont have to hardcode anything. and it does not matter howmany companies or how many products are there.

This is only go give you an idea .Hope that solves your problem.
If you still have doubts then please post back.

i'm sorry to say this but i can't understand anything.... i am self taught using online tutorials only....

suppose in a table u store all the company names and in another table all there products.

now in the form load read all the company name name from table1. whwn u change the selection in the combo ,u need to execute the select command in database and select only the related products of the selected company only.

In this case you dont have to hardcode anything. and it does not matter howmany companies or how many products are there.

This is only go give you an idea .Hope that solves your problem.
If you still have doubts then please post back.

what code do i have to use to do this?

create two tables in access
1 tblbrand
2 tblmodel
tblbrand has one column called brandname with all the brandnames
tblmodel has two columns called brandname and model
enter all the models in model column and in same row in brandname column enter brandname of that model
In your vb project use adodc to connect to the access tables. Load all brandnames from tblbrand in first combo.
When user choses a brandname load all models from tblmodel where brandname is equal to brandname chosen.

do you know how to use adodc?

ok first you make a table for cars brand then another table for car's brand details.
Example:
table1 = Car Brand Table
table2 = Car Brand Details Table

Let's say you have a Combo Box name cboCarBrand and other combo box name cboDetails. then put this code: (note: I use DAO to connect in the MS Access database, if use other connection then modify it..)

Private Sub cboCarBrand_Click()
Dim tmpRs as Recordset

Set tmpRs=dbase.OpenRecordset("Select * from [Car Brand Details Table] where CarBrand='" & cboCarBrand.Text & "'")
If Not tmpRs.BOF Then
      cboDetails.Clear
      While not tmpRs.EOF
         cboDetails.AddItem tmpRs!Details
         tmpRs.MoveNext
      Wend
End If
End Sub

ok thnx,..... il will try that out

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.