Advanced combo boxes on form please help!! (1 Viewer)

The_Freak

New member
Local time
Today, 12:34
Joined
May 16, 2001
Messages
8
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

Super Moderator
Staff member
Local time
Today, 07:34
Joined
Feb 19, 2002
Messages
43,293
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

New member
Local time
Today, 12:34
Joined
May 16, 2001
Messages
8
Looked already in northwinds.mdb but couldnt find the answer....
 

ntp

Registered User.
Local time
Today, 12:34
Joined
Jan 7, 2001
Messages
74
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
 

Users who are viewing this thread

Top Bottom