View Full Version : 2 Selection


Haytham
11-26-2001, 12:09 PM
Hi All...
Will anybody help in creating 2 combo box selection.
In one field, it's a combo box of fruits, vegetables, etc..
So if I choose fruits, the other field (also combo box) should select one of the fruits and not other data.
Thanks

jwindon
11-26-2001, 01:24 PM
I think before I would go any further explaining this to you, I would like to see the table structures of the tables that have the values for which the combos will get their values. I would also need the form name.

Pat Hartman
11-26-2001, 07:06 PM
The query for the second combo box needs selection criteria that references the selected value of the first combobox. In the criteria cell of the correct field use the following syntax:
=Forms![YourFormName]![YourComboBoxName]
Then in the AfterUpdate event of the first combo, requery the second combo.

Haytham
11-28-2001, 05:44 PM
Hi Again,
Well, I have two tables, first is TypeTable contains only one field called: Type. Second is ItemTable contains two fields : Type and Items.
In ItemTable I put the items like potato, cucumber, etc… under Vegetable’s Type and so on.
I have a form called Main created from Main Table contains two lookup fields with many others fields. So, if I choose in the Type Field : Vegetables I should get only those specified under Vegetable Type in the second Lookup Field.
Hope the point is clear.
Many thanks in advance.

Dear Partman, sorry I tried to apply the requery but failed. I know I have something wrong

jwindon
11-29-2001, 04:30 AM
The structure, as you explained it, seems a bit off. Should be something like this:

tblCustomers
CustomerID (PK)
CustomerName
address, etc.


tblItemTypes
TypeID (PK) autonumber
TypeOfItem - text

tblItems
ItemNo (PK) - auto or text based on need
TypeID (FK) - lookup

tblOrder (frmMainForm basedon this)
OrderNo (PK) - auto
CustomerID -lookup
ItemNo - lookup
Qnty
OrderDate - date/time
etc.


On your form, you need an unbound combo that selects from tblItemTypes - both fields.

The second combo should be built using tblItems. During the wizard, choose to store the value in [ItemNo]. Then,

Right click on its properties and hit the build button next to Recordsource. In the query grid that shows and under the field [ItemType] put =Forms!frmMainForm![ComboBoxName1]

On the AfterUpdate event of combobox1, put the code, Docmd.RunCommand acCmdRefresh

Hope I wrote that all down correctly. Its still early for me today!

Good luck!

Haytham
11-29-2001, 01:48 PM
Dear jwindon,
Thank you again..
My db is much simpler than the structure thought.
I send you a copy of it.

jwindon
11-29-2001, 03:09 PM
Well.....don't know why I went off with that Orders thing...must have been thinking of something else. There's been a lot of the Customers - Orders thing going on lately.

Anyway, the method I posted will work for any case, so long as the ItemType can be related to the Item.

jwindon
11-30-2001, 06:38 AM
Sent you back the example. Uses the value of the first combo to filter the second combo in the rowsource property of the second combo.

Is that what you wanted?

Haytham
12-02-2001, 10:36 AM
Hi jwindon,
Yes that what I want, but it is not filtered.
Still, I can see the combo of all the types and not only the filtered one.
Maybe I'm still confused. I'll go th' your code more.
Thank you

jwindon
12-02-2001, 06:47 PM
I'm must have misunderstood what you were wanting?

Combo2 is filtering based on the choice in combo1.

Are you checking this on a new record? The second combo will not filter until the AfterUpdate event of the first combo is fired.