w860098
I am surprized that you did not post this problem in...
Microsoft: Access Forms Forum
I believe what you are attempting to do is called "Cascading combo boxes"...
There is an FAQ on the topic...
Combo Box - dependant on another Combo Box
You have not provided much in the way of specifics, so I will improvise...
Suppose you want to list students by grade. You select a grade in the first list box or comb box and the second list box or combo box displays the students in the selected grade.
Assumptions...
tblStudent
StudentID - primary key
StudentName
StudentGradeCode - foreign key to tblGrade
tblGrade
GradeCode - primary key
cmbGrade - combo box based tblGrade, RowSource is
SELECT GradeCode FROM tblGrade ORDER BY GradeCode
cmbStudent - combo box based on tblStudent.
Initial RowSource is...
SELECT StudentID, StudentName FROM tblStudent ORDER BY StudentName
The end-user wants to search only for the Grade 6 students.
They select "Grade 6" from cmbGrade. This fires off an EventProdcedure AfterUpdate which dynamically tweaks the RowSource for cmbStudent.
How? The form is open in design mode, and the properties window is open ("View" -> "Properties") Select cmbGrade combo box, click on the "Events" tab, select the "AfterUpdate" field, select "[Event Procedures]" from the pick list, and then click on the "..." command button that appears to the right. This will take you to the VBA coding window.
Code:
Dim strSQL as String, strQ as String
strSQL = "SELECT StudentID, StudentName FROM tblStudent"
strQ = Chr$(34) 'Double quote character
If Len(Nz(cmbGrade, "")) Then
strSQL = strSQL & " WHERE StudentGrade = " & strQ & Me.cmbGrade & strQ
End If
strSQL = strSQL & " ORDER BY StudentName"
Me.cmbStudent.RowSource = strSQL
Me.cmbStudent.Requery
The resulting SQL statement for the above example is...
SELECT StudentID, StudentName FROM tblStudent
WHERE StudentGrade = "Grade 6"
ORDER BY StudentName
If GradeCode is numeric, the WHERE clause would be...
Code:
If (Nz(cmbGrade, 0)) Then
strSQL = strSQL & " WHERE StudentGrade = " & Me.cmbGrade
End If
Hope you can apply this example to your own situation.
Richard