I would put the code in the cboPhysician's AfterUpdate event, not in the Dirty event. You cannot place a control source on a textbox at design view because it will prevent you from assigning it a value on the fly. If the textbox is bound to the data table, you assign a value to it in VBA at runtime.
Code:
Dim strRowSource as String
If Len(Nz(Me.cboPhysician, "")) = 0 Then
'No Physician Chosen. Make the rowsource ALL specialties.
strRowSource = "SELECT DISTINCT [Specialty] FROM Physicians ORDER BY [Specialty]"
Else
'Physician chosen. Find his/her specialty.
strRowSource = "SELECT DISTINCT [Specialty] FROM Physicians WHERE [Physician] = '" & Me.cboPhysician & "' ORDER BY [Specialty]"
End If
Me.cboPhysicianSpecialty.RowSource = strRowSource
If Me.cboPhysicianSpecialty.ListCount = 1 Then
'The physician has only one specialty. Enter it automatically.
Me.cboPhysicianSpecialty = Me.cboPhysicianSpecialty.Column(0,0)
End If
Note the use of DISTINCT and ORDER BY in the rowsource assignment.
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division