Hi Rain, I tried to follow your instructions, but I couldn’t make it work.
I started with the AgencyProgram table, and I broke it out into two tables: tblAgy and tblPgm. Each of them now has an autonumber primary key. I used field names with the suffixes PK and FK to designate primary and foreign keys . Then I recreated the query qryAgyPgm, and bound the menu form frmEditAgys, to this query. The first combo box has as its control source the field AgencyName, and the second has ProgramName from this query. The row source for the first combo box, cboEditAgy, is the AgencyName field from tblAgy. The row source for the second combo box, cboEditPgm, is a query based on the two (related) tables to limit the programs displayed to those that belong to the agency shown in the first combo box. When I select an agency for the first combo box, I get this error message.
Run-time error ‘-2147352567 (80020009)’: Cannot add record(s): Join key of ‘tblPgm’ not in record set.
Each time this happens, I reconstruct the row source query in the second combo box, and the combo boxes work until I close the form and reopen it. Then I get the same error message. When it does work, and I modify a record, Access adds a new record to the table rather than changing the existing record. I can’t delete a record.
I also reconstructed the alternate approach, unfortunately, also without success. I started with the AgencyProgram table, and I broke it out into three tables: tblAgyc; tblPrgm; and tblLookupAgcyPrgm. The third table has only two fields, a lookup to tblAgcy and a lookup to tblPrgm. At first I tried binding the menu form, frmEditAgysAlt, to the table tblLookupAgcyPrgm, but I found that if I bound the combo boxes to the two lookup fields, I’d get a type mismatch. Instead, I created a query that joined tblAgcy with tblPrgm. I set the control source for the first combo box, cboEditAgy, to the AgencyName field in tblAgcy, and the control source for the second combo box to ProgramName in tblPrgm. I created a query for the row source for the second combo box that joined the two tables, and filtered ProgramName on the contents of the first combo box. Since the tables aren’t directly related—they’re each related to the lookup table—I had to relate them on their primary keys. When I tested this and selected an agency in the first combo box, I got one choice of an unrelated program in the second box.
I’m attaching a zipped copy of the DB.
Thanks,
Henry