You can use the Enabled property and the Tag property of those fields affected.
For those fields on the form that must be enabled when the user selects the Project or Program combobox, place the word "Program,Project" in the Tag property of each control. For those fields that must be enabled when the user selects the Team combobox, place the word "Team" in the Tag property of each of the fields. We also create a procedure to either enable the fields or not enable them, depending on which combobox is selected. The name of the procedure is EnableDisableControls.
Name your comboboxes as follows:
Project cboProject
Program cboProgram
Team cboTeam
We will use part of the name of the comboboxes to determine which fields on the form should be enabled and which should not.
Here is the Code:
Private Sub EnableDisableControls(strCtl As String)
Dim ctl As Control
' Enumerate through each control to see if the values
' in the Tag property equals the name of the combobox
' (minus the cbo portion of the name, Enable the field.
For Each ctl In Me.Controls
If InStr(ctl.Tag, Right(strCtl, Len(strCtl) - 3)) > 0 Then
ctl.Enabled = True
' If the tag property is not equal to the name of
' the combobox less the cbo) but there is something
' in the tag property, Disable the field.
ElseIf Len(ctl.Tag) > 0 Then
ctl.Enabled = False
End If
Next ctl
End Sub
Private Sub cboProject_AfterUpdate()
Dim ctl As Control
Set ctl = Screen.ActiveControl
' Call the procedure to enable/disable controls
EnableDisableControls (ctl.Name)
End Sub
Private Sub cboTeam_AfterUpdate()
Dim ctl As Control
Set ctl = Screen.ActiveControl
' Call the procedure to enable/disable controls
EnableDisableControls (ctl.Name)
End Sub
John Ruff - The Eternal Optimist
