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

Clearing combo boxes

Status
Not open for further replies.

Steven811

Technical User
Apr 15, 2004
76
GB
Hi

I have constructed a form that consists of 4 cascading cbo boxes and 2 subforms.

When I have made my final selection in the last combo and go back and choose another record from the first combo I requery the second combo, this leaves the records in the other combo boxes and subforms.

How do I alter my code to requery the combo boxes and subforms so that they clear and can not be edited.

Steven811
 
Hi Chance

Which event on what control would I place the code?

Regards

Steven811

PS - Had a quick look at your web site, I'll dl it later.
 
Don't forget to requery your combo box or subform.

yourcombobox.requery
 
Can I requery more than one combo or form on the same event?

What would the code look like?

Thanks
 
Yes...

AfterUpdate()

yourcombo1.rowsource = ""
yourcombo1.requery
yourcombo2.rowsource = ""
yourcombo2.requery

yoursubform.filter = ""
yoursubform.filteron = false
yoursubform.requery
 
yourcombo1.rowsource = ""

will clear the items in your subsequent comboboxes. If this is what you're after, then it works.

If you want the subsequent comboboxes to clear the current entry, but to keep the corresponding source, then use:

yourcombo1 = ""
yourcombo1.requery
etc.
 
One similar problem I'm having is requery on a subform. I have a form/subform. The form has two cascading comboboxes. I select [state] first, then [city], the source of [city] changes based on the [state] selected. I want the subform then to list pricing for each city.

I've tried (but get a debugging error "Object Required"):
city_AfterUpdate()
pricing.requery

My parent/child are linked through [city].

Any suggestions?
 
Hi,

If you are trying to requery a subform from an event on the parent form, then use the following syntax and show the entire form heirarchy:

Forms!FormName!SubFormName.Requery

A couple of other suggestions: use some sort of naming convention in your code to make it more readable. You can use your own, but there are a couple of good ones already in widespread use.

frmPricing for a form
tblPricing for a table
cboPricing for a combo box

Then someone looking at the code will have a clue as to what "Pricing" is.

And last, anytime the rowsource of a list/combo box is changing, it automatically requeries. The additional line of .requery code becomes redundant.

Cheers,
Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top