Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deactivate fields on form 2

Status
Not open for further replies.

cairo207

IS-IT--Management
Jan 2, 2003
13
I have inherited a database for the capture of work-related incidents. A STATUS combo box identifies whether an incident is Open or Closed. What I want to do is when an incident is Closed it prevents entries into any of the other field/combo boxes on the form leaving the STATUS combo box as the only object that can be changed. Once the STATUS is changed back to Open it reactivates all other fields/combo boxes.

Thanks,
 
Try:
Code:
Private Sub myComboBox_Change()
    myTextBox1.Enabled = myComboBox = "Open"
    myTextBox2.Enabled = myComboBox = "Open"
    ...
End Sub
If you don't want them to 'look' disabled, you can try:
Code:
Private Sub myComboBox_Change()
    myTextBox1.Enabled = myComboBox = "Open"
    myTextBox1.Locked = myComboBox <> "Open"
    
    myTextBox2.Enabled = myComboBox = "Open"
    myTextBox2.Locked = myComboBox <> "Open"
    ...
End Sub
You could also use the Tag property of any control whose Enabled property you want to toggle, and loop through all the form's controls, applying the setting only if the Tag property has been set.

Max Hugen
Australia
 
Hello cairo,

Here's another option in addition to Max's suggestion. You could add other control types to the If statement depending on what you have on your form. You have to check the control type because the enabled property isn't valid for all controls. There might be a better way to do it, but this code should work. My example assumes that the value "Open" or "Closed" is stored in column 1 of your combo box.

Code:
Dim item As Variant

For Each item In Controls
     If (item.ControlType = acCheckBox) Or (item.ControlType = acComboBox) Or (item.ControlType = acListBox) Or (item.ControlType = acTextBox) Then
         If (item.Name <> "cbo_status") And (cbo_status.Column(1) = "Closed") Then
               item.Enabled = False
         Else
               item.Enabled = True
         End If
    End If
Next

If Status is the only combo box on your form, you could simplify the code with:

Code:
Dim item As Variant

For Each item In Controls
     If (item.ControlType = acCheckBox) Or (item.ControlType = acListBox) Or (item.ControlType = acTextBox) Then
         If (cbo_status.Column(1) = "Closed") Then
               item.Enabled = False
         Else
               item.Enabled = True
         End If
    End If
Next



dz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top