I spent hours on this and I’m defeated. I expect the answer is simple, if not I’ll just have to think of another approach. But if anyone knows the answer (and understands what I’ve written, I’ve tried to be clear and simple!) you will make me very, very happy!
I have three tables, simplified for explanation:
Table: Countrys (Based on ISO3166-1)
Fields: CountryID, CountryName
Table: Subdivisions (Based on ISO3166-2)
Fields: SubdivisionID, SubdivisionName, CountryID
Table: Locations (Based on UN/LOCODE)
Fields LocationID, LocationName, CountryID, SubdivisionID
The problem I can’t figure out is the Form for ‘Locations’ Table. (And I have this same scenario for other forms, so would be very useful to understand the how to get this right)
If I select an option from the ‘Country’ combo box (cbocountry) on the Locations form, then I want the Subdivision combo box (cbosubdivision) to filter records to show the same CountryID.
I’ve tried adding 'criteria' to the CountryID field in query builder for the cbosubdivison: [Forms]![locations]![cbocountry]
And VBA to the cbocountry:
Private Sub cbocountry_Change()
cbosubdivision.Requery
End Sub
And whilst that works, it filters all the records on a continuous or split form, so that’s no good.
Do I need to clear the filter on record change somehow? Although I expect that would fix the issue when moving to one record to another. But not solve the continous/split form problem.
And if so not use continuous or split forms? Instead using a subform and a separate datasheet or continuous form to find and select a record?
Not quite sure how to go about that yet, but if that’s what’s needed...
Or is there some clever VBA code I need to learn that I haven't found in my searches?
I have three tables, simplified for explanation:
Table: Countrys (Based on ISO3166-1)
Fields: CountryID, CountryName
Table: Subdivisions (Based on ISO3166-2)
Fields: SubdivisionID, SubdivisionName, CountryID
Table: Locations (Based on UN/LOCODE)
Fields LocationID, LocationName, CountryID, SubdivisionID
The problem I can’t figure out is the Form for ‘Locations’ Table. (And I have this same scenario for other forms, so would be very useful to understand the how to get this right)
If I select an option from the ‘Country’ combo box (cbocountry) on the Locations form, then I want the Subdivision combo box (cbosubdivision) to filter records to show the same CountryID.
I’ve tried adding 'criteria' to the CountryID field in query builder for the cbosubdivison: [Forms]![locations]![cbocountry]
And VBA to the cbocountry:
Private Sub cbocountry_Change()
cbosubdivision.Requery
End Sub
And whilst that works, it filters all the records on a continuous or split form, so that’s no good.
Do I need to clear the filter on record change somehow? Although I expect that would fix the issue when moving to one record to another. But not solve the continous/split form problem.
And if so not use continuous or split forms? Instead using a subform and a separate datasheet or continuous form to find and select a record?
Not quite sure how to go about that yet, but if that’s what’s needed...
Or is there some clever VBA code I need to learn that I haven't found in my searches?