Combobox get value and filter another combobox (1 Viewer)

hugomadail

Registered User.
Local time
Today, 16:17
Joined
Aug 31, 2018
Messages
25
Hello, in my database I have a form (frmStores) with 2 combobox:

cbRegion
- Lists RegionName and RegionID from tblRegions
- This combobox is unbound

cbPlace
- Lists PlaceName, PlaceID and RegionID from tblPlaces

In database, tblRegion is related with tblPlaces because tblPlaces has field RegionID and each place belongs to a region only.
There is tblstores where frmStores gets all data. tblStore has PlacesID field because its associated to a place. I didnt add a RegionID field because the place ID is already associated with a region.

In form frmStores, when opening/moving to next record, I want to:
1) unbound cbRegion get RegionID from cbPlace "maybe [cbPlace].Column(3) ?" so it would show a number if place has region association or be empty if there is no association
2) cbRegion filter cbPlace to only show Places from that RegionID since we got the RegionID on 1). If it was empty on 1), cbPlaces would drop-arrow results would be empty yoo
3) When moving to another record in frmRegion, 1) and 2) must work as described too.

(This would be easy if tblStores had RegionID too because Region would be auto shown on frmStores and then I would use [cbRegion] as criteria to cbPlace source, but I'm trying to avoid that, I want DB to have field reduction - if Store is assigned to a place, that place is already suposed to be in a specific region, so add regionID to tbl Stores would be a second location field)

I hope explanation was clear, can someone help ?
 

isladogs

MVP / VIP
Local time
Today, 16:17
Joined
Jan 14, 2017
Messages
18,209
Cleary you need cascading combos but I got lost with your explanation.

Can you summarise what the table fields are.
Also the row sources for each combo.
 

hugomadail

Registered User.
Local time
Today, 16:17
Joined
Aug 31, 2018
Messages
25
here it is:

tblStores:
StoreID
StoreName
PlaceID (association with tblPlaces)

tblRegions:
RegionID
RegionName

tblPlaces:
PlaceID
PlaceName
RegionID (association with tblRegions)


frmStores (from tblStores), comboboxes:

cbRegions (unbounded, doesnt store value selected)
RegionID, RegionName from tblRegions
(show only RegionName but uses RegionID for data)

cbPlaces (source tblPlaces)
PlaceID,PlaceName, RegionID from tblPlaces
(RegionID was for filtering purposes but not working)
(show only RegionName but uses RegionID for data)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:17
Joined
May 7, 2009
Messages
19,233
maybe something like this.
see the rowsource of the 2 combo.
view also the code on tbe sample form.
 

Attachments

  • StoreSample.zip
    28.7 KB · Views: 50

hugomadail

Registered User.
Local time
Today, 16:17
Joined
Aug 31, 2018
Messages
25
arnelgp, attached file is exactly what I wanted! I copied to my DB and everything works as expected, but I made just a small change for new records because by default it would show the first Region in cbRegion and I prefer field empty (used "Me.cbRegion = Null").

Thanks!
have a nice day :)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:17
Joined
May 7, 2009
Messages
19,233
glad you got it.
 

Users who are viewing this thread

Top Bottom