I need a set of cascading combo box on my form. The user will be entering data about cases belonging to social service agencies. The user needs to enter the name of the agency and then the name of a program run by that agency. The names of the agencies and their programs are in a table called tblAgyPgm. The field names are AgencyName and ProgramName. The combo boxes are called cboAgency and cboPgm. The form runs off a query that combines a main table containing the basic case information with a related table that holds the program information (many to one) and one related to it that holds agency information (one to many) for each case.
I set the control source for cboAgency as the AgencyName field on the form and for cboPgm as ProgramName. In the cboAgency combo box I set the row source as:
SELECT DISTINCT tblAgyPgm.AgencyName FROM tblAgyPgm ORDER BY tblAgyPgm.AgencyName;
For After Update, I entered the following code:
Private Sub cboAgency_AfterUpdate()
On Error Resume Next
cboPgm.RowSource = "Select tblAgyPgm.ProgramName " & _
"FROM tblAgyPgm " & _
"WHERE tblAgyPgm.AgencyName = '" & cboAgency.Value & "' " & _
"ORDER BY tblAgyPgm.ProgramName;"
End Sub
I tested this with records that are already in the table. The cboAgency combo box populates with the name of the agency in the Agency Name field, and when I click the down arrow, it displays the list of agencies. I set the control source for the cboPgm combo box to Program Name, and it shows the name of the program. But when I click on the down arrow, it doesn’t show a list of programs.
Access automatically starts the code with: Option Compare Database. I’ve tried both and without this line. Neither way works.
The other part of the problem is that I need to populate the agency and program information fields, but neither are fields in the main table, only lookups to the separate, related tables that store this information.
Many thanks for any help.
I set the control source for cboAgency as the AgencyName field on the form and for cboPgm as ProgramName. In the cboAgency combo box I set the row source as:
SELECT DISTINCT tblAgyPgm.AgencyName FROM tblAgyPgm ORDER BY tblAgyPgm.AgencyName;
For After Update, I entered the following code:
Private Sub cboAgency_AfterUpdate()
On Error Resume Next
cboPgm.RowSource = "Select tblAgyPgm.ProgramName " & _
"FROM tblAgyPgm " & _
"WHERE tblAgyPgm.AgencyName = '" & cboAgency.Value & "' " & _
"ORDER BY tblAgyPgm.ProgramName;"
End Sub
I tested this with records that are already in the table. The cboAgency combo box populates with the name of the agency in the Agency Name field, and when I click the down arrow, it displays the list of agencies. I set the control source for the cboPgm combo box to Program Name, and it shows the name of the program. But when I click on the down arrow, it doesn’t show a list of programs.
Access automatically starts the code with: Option Compare Database. I’ve tried both and without this line. Neither way works.
The other part of the problem is that I need to populate the agency and program information fields, but neither are fields in the main table, only lookups to the separate, related tables that store this information.
Many thanks for any help.