Private Sub Form_Open(Cancel As Integer)
[COLOR="DarkGreen"]'Fill the Semester Combo Box with distinct semesters
'contained within the Table
'Ensure tha the Row Source Type s set to Table/Query.[/COLOR]
Me.cboSemester.RowSourceType = "Table/Query"
[COLOR="DarkGreen"]'Place a SELECT query into the RowSource of the Semester
'combobox to retrieve the all the different Semesters in
'Table. The DISTINCT statement is used to ensure that no
'duplicate items are listed.[/COLOR]
Me.cboSemester.RowSource = "SELECT DISTINCT Semesters FROM [COLOR="Red"][I]WhateverYourTableIsNamed[/I][/COLOR] " & _
"ORDERED BY Semesters;"
[COLOR="DarkGreen"]'Ensure that the Department combo box is set to Table/Query.
'This is actually default and should not be required![/COLOR]
Me.cboDepartment.RowSourceType = "Table/Query"
[COLOR="DarkGreen"]'Disable both the Department Combo and the Enrollment Count
'Text Box to ensure that the Semester is selected first.[/COLOR]
Me.cboDepartment.Enabled = False
Me.txtEnrollmentCount.Enabled = False
End Sub
Private Sub cboSemester_Click()
[COLOR="DarkGreen"]'Does the Semester ComboBox actually contain anything?
'If so then....[/COLOR]
If IsNull(Me.cboSemester) = False Then
[COLOR="DarkGreen"]'Set the RowSource property for the Department ComboBox.
'Again, a SELECT query is used for this and again, the
'DISTINCT statement is used to ensure that duplicate
'departments are not added to the list. Only Departments
'matching the Semester are listed. Within the ComboBox we
'also add a second column for the Enrollment Count for each
'listed Department.[/COLOR]
Me.cboDepartment.RowSource = "SELECT DISTINCT Department,EnrollmentCount FROM [COLOR="Red"][I]WhateverYourTableIsNamed[/I][/COLOR] " & _
"WHERE Semester='" & Me.cboSemester & "' ORDERED BY Department;"
[COLOR="DarkGreen"]'Enable the Department ComboBox so that now
'something can be selected from that box.[/COLOR]
Me.cboDepartment.Enabled = True
End If
End Sub
Private Sub cboDepartment_Click()
[COLOR="DarkGreen"]'Once the department is selected, pull out the Enrollment
'Count from the second Combo Column and place it into the
'Enrollment Count Text Box.[/COLOR]
Me.txtEnrollmentCount = Me.cboDepartment.Column(1)
[COLOR="DarkGreen"]'Now enable the Enrollment TextBox[/COLOR]
Me.txtEnrollmentCount.Enabled
End Sub