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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

One combo box dependng on another combo box

Status
Not open for further replies.
Jan 10, 2005
30
US
I have two combo boxes on my form. I would like the selection list of the 2nd combo box to display values that are valid for the selected item in combo box 1.

For example, let's say Combo Box 1 shows a list of states. When a particular state is selected in Combo Box 1, I want Combo box 2 to display valid cities for the selected state. How can I do this on my form?

Thanks,
M
 
faq702-4289 and hundreds of posts in these forums. have a search.

________________________________________
Zameer Abdulla
Visit Me
There is only one perfect child in this world. Every mother has it.
 
Thanks, I now have the two comboxes working as desired. The values listed in combo box 2 are based on the item selected in Combo box 1 which is what I wanted.

I have another question, how can I make sure that combo box 2 always selects the first item on the list in other words, I don't want combo box 2 to show blank in the text box)? Right now, when I select a value in combo box 1 and then drop down combo box 2, I see the correct values in combo box 2 but nothing is selected by default. I want to make sure that there is a value selected in combo box 2 at all times. I know how to do this the first time the form loads. I set the value for combo box 1 and also set the corresponding value for combo box 2. But after the forms loads and the value of combo box 1 is changed by the user, I want to make sure that combo box 2 shows the 1st item from its list as the selected value.

Thanks
M
 
Something like this?
Private Sub Form_Open(Cancel As Integer)
Me.Combo2.Value = DLookup("FieldName", "TableName")
End Sub
for more on Dlookup pls refer to help

________________________________________
Zameer Abdulla
Visit Me
There is only one perfect child in this world. Every mother has it.
 
In the AfterUpdate event procedure of Combo1:
Combo2.RowSource = ...
Combo2.SetFocus
Combo2.ListIndex = 0

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I have the following lines in the AfterUpdate event of Combo1:

Combo2.Requery
Combo2.SetFocus
Combo2.ListIndex = 0

I get the following error:

"Run-time error '7777'. You've used the ListIndex property incorrectly".

Any idea, why?

Thanks
M
 
And this ?
Combo2.Value = Combo2.ItemData(0)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top