combo box based on another combo box

D

Darhl Thomason

I would like to have a combo box based on another combo box on my form. In
my tables, I have a Region table with two Regions; I have a District table
with 5 districts. Table structure is:

tblRegion
RegionID RegionName
1 Western
2 Central

tblDistrict
DistrictID DistrictName RegionID
1 Mountain 2
2 Northern Plains 2
3 Pacific 1
4 NorthWest 1
5 MidWest 2

What I want is to have the Region combo box control what shows in the
District combo box. For example, if I select the Western Region, I only
want the Pacific and NorthWest Districts to show. And if I select the
Central Region, I only want the Mountain, Northern Plains and MidWest
Districts to show.

The RowSource for the Region combo box is:
SELECT tblRegion.RegionID, tblRegion.RegionName FROM tblRegion ORDER BY
tblRegion.RegionName WITH OWNERACCESS OPTION;

The RowSource for the District combo box is:
SELECT tblDistrict.DistrictID, tblDistrict.DistrictName FROM tblDistrict
ORDER BY tblDistrict.DistrictName WITH OWNERACCESS OPTION;

My DB is programmed in VBA and is an Access2003 file format.

Thanks!

Darhl
 
A

Amy Blankenship

Darhl Thomason said:
I would like to have a combo box based on another combo box on my form. In
my tables, I have a Region table with two Regions; I have a District table
with 5 districts. Table structure is:

tblRegion
RegionID RegionName
1 Western
2 Central

tblDistrict
DistrictID DistrictName RegionID
1 Mountain 2
2 Northern Plains 2
3 Pacific 1
4 NorthWest 1
5 MidWest 2

What I want is to have the Region combo box control what shows in the
District combo box. For example, if I select the Western Region, I only
want the Pacific and NorthWest Districts to show. And if I select the
Central Region, I only want the Mountain, Northern Plains and MidWest
Districts to show.

The RowSource for the Region combo box is:
SELECT tblRegion.RegionID, tblRegion.RegionName FROM tblRegion ORDER BY
tblRegion.RegionName WITH OWNERACCESS OPTION;

The RowSource for the District combo box is:
SELECT tblDistrict.DistrictID, tblDistrict.DistrictName FROM tblDistrict
ORDER BY tblDistrict.DistrictName WITH OWNERACCESS OPTION;
try

SELECT tblDistrict.DistrictID, tblDistrict.DistrictName FROM tblDistrict
WHERE tblDistrict.RegionID LIKE IIF(Me.RegionID IS NOT NULL, Me.RegionID,
"*")
ORDER BY tblDistrict.DistrictName WITH OWNERACCESS OPTION;

Then put

Me.District.Requery

in the Region combobox's AfterUpdate

HTH;

Amy
 
D

Darhl Thomason

Thanks Graham!

That did the trick. I've bookmarked your page, hopefully I can use your
page for other reference ideas.

Darhl
 

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