View Full Version : Advanced combo boxes on form please help!!


The_Freak
05-16-2001, 06:15 AM
Hello,

Lets say i want two combo boxes on my form.

In combo box oone you can select the values:

A
B
C
D

In the second combo box i want to select values which belongs by the above clicked value.

Lets's say If i click on the first Combo box A

then i want to select in the second combo box
1
2
3

If i select B in the first combo box i want to select

4
5
6

If i Select C in the first combo box i want to select

7
8
9

Any body know how to do this?

Pat Hartman
05-16-2001, 06:20 AM
This question has been answered many time here recently. Look in northwinds.mdb or solutions.mdb for an example of how to do this.

The_Freak
05-16-2001, 06:23 AM
Looked already in northwinds.mdb but couldnt find the answer....

DES
05-16-2001, 06:25 AM
For a sample of this and other things go to:
http://www3.sympatico.ca/qaissuper/Index.html

Its all free, as it should be!

ntp
05-16-2001, 06:31 AM
You will need to use the AfterUpdate event of the first combo box, combo1, to set the recordsource of the second combo box, combo2.

e.g. Private Sub Combo1_AfterUpdate()
me.combo2.enabled = true
me.Combo2.recordsource = "SELECT tableb.FieldA, TableB.FieldB FROM TableB WHERE TableB.FieldA ='" & me.combo1 & "'"
me.combo2.requery
End Sub

This assumes you have two tables the first table has a list of values. This is the recordsource of your first combobox, Combo1.
The second table has two fields, one linking to a value from the first table and the second some other value. This table will be used in the creation of a record source for your second combobox, combo2.

Also in the form load event have the line me.combo2.enabled = false. This will prevent the user from trying to select anything from the second combo box until an item from the first combo box is selected.

This solution depend on you having your dat in two tables but is not a neccesity. The principle still holds in any other case. You will need to use the afterupdate event to modify the second combo box to suit the value of the first combo box


ntp