Populate combo box from code
Posted on 2014-01-08
I am attempting to populate a combo box based on values chosen in two other combo boxes. When I run the generated SQL from the code I get correct values. The combo box remains blank however, if I manually use the drop down arrow, the value is there and I can chose it but I need it to set the combobox value automatically. Requery doesn't seem to do it...
How can I modify it so that it doesn't just generate the value but also sets it as the combo box choice?
Private Sub Course_Name_AfterUpdate()
Dim strSQL As String
If IsNull(Me![Course Name]) Then
Me.[CourseID].RowSource = ""
strSQL = "SELECT tblCourses.[CourseID] FROM tblCourses WHERE tblCourses.[Course Name] = '" & Me![Course Name] & "'" & " AND tblCourses.category = '" & Me![Category] & "'"
Me.[CourseID].RowSource = strSQL