Dynamically update a combo box list

G

Guest

Hi all,

I have two tables, say one is tblCountry, the other one is tblCity.
tblCountry and tblCity has a one-to-many relationship.

Now I want to build a form with two combo boxes, one (cboCountry) for the
CountryName field from the tblCountry and the other one (cboCity) for the
CityName field of the tblCity. I want the list for the cboCity be
automatically updated whenever a value of cboCountry is changed. How can I do
this using macro (not VBA)? Thanks a lot in advance.
 
D

Dirk Goldgar

In
Fred said:
Hi all,

I have two tables, say one is tblCountry, the other one is tblCity.
tblCountry and tblCity has a one-to-many relationship.

Now I want to build a form with two combo boxes, one (cboCountry) for
the CountryName field from the tblCountry and the other one (cboCity)
for the CityName field of the tblCity. I want the list for the
cboCity be automatically updated whenever a value of cboCountry is
changed. How can I do this using macro (not VBA)? Thanks a lot in
advance.

Why not VBA? Well, never mind. But if you define cboCity's RowSource
property to refer to the cboCountry as a criterion, then all you have to
do is requery cboCity in the AfterUpdate event of cboCountry. The macro
action Requery with the Control Name argument "cboCity" ought to take
care of that.

If this is a bound form, you probably also have to requery the combo box
in the form's Current event.
 
G

Guest

Fred,

I encourage you to investigate VBA; it is not conceptually difficult, is
much more flexible and rich, and permits error-handling to avoid crashing
when something occurs that you didn't anticipate.

In VBA, Dirk's solution would be:

' Me! is an Access-supplied reference to the current form
' [YourComboBox] is the combo box' Name property
' .Requery applies the Requery method to the combo box

Me![YourComboBox].Requery

Sprinks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top