Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need code to change second combo box based on 1st combo box selection 1

Status
Not open for further replies.

jamason07

IS-IT--Management
Aug 28, 2003
46
US
Good Morning!

I have two combo boxes, cbo1 and cbo2. cbo1 has three possible selections based on a query: list A, list B or list C. I need cbo2 to display the contects of the appropriate list dependent on the selection of cbo1. I have seen this done on several websites that ask for user information. For example, they will ask what country you are from, when you select "United States" in the first combo box, the second combo box will then show all the states. When you select which state you are from in the second combo box, the third combo box will show the cities in that state, etc. I need this option in my database so as not to have a giant list of selections in my combo boxes and allow users to quick select based on which list they need. Suggested code? Thanks in advance!

JAM
 
You need to have a relationship in the data this like:

tblList

ID ListName
1 ListA
2 ListB
3 ListC


tblListDetail

ListID ListItem
1 Item1
1 Item2
1 Item3
2 Item4
2 Item5
3 Item6
3 Item7
3 Item8

On your form have a combobox: cboList with tblList as it's rowsource or preferably a query that selects all from tblList as the rowsource. Make ID the bound column, give it a width of 0 (columnwidths property entry should be something like 0;1.5)

Have the rowsource of the second combobox (cboListDetail) be:

Select ListID, ListItem
From tblListDetail
Where ListId = forms!YourForm!cboList

Make ListID the bound column, give it a width of 0 (columnwidths property entry should be something like 0;1.5)

Then in the AfterUpdate event of cboList put:

cboListDetail.Requery

HTH
 
Awsome! Worked like a charm! My users will thank you!

JAM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top