Link to home
Start Free TrialLog in
Avatar of gigifarrow
gigifarrow

asked on

Code for greying out the form is not working

The greyed out field is based on the model number that is in a drop down box. Once the model number is selected then certain fields are greyed. In my code  I have two model numbers,"A3 BFIST" and  "M2A2" then in the code I have two fields one is enabled based on the model number.


Private Sub Form_Current()

If Model = "A3 BFIST" Then
Me.verification.Enabled = True

Else
'The field you want to keep open
 Me.doorMod.Enabled = False
End If

If Model = "M2A2" Then
'The field you want to keep open
 Me.doorMod.Enabled = False
End If


End Sub
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Try the following sub (it starts with the controls enabled, and then disables specific controls based on the value of the Model combo) - you will have to edit it as shown in the comments to disable speific controls.  The sub needs to be called from the Form's current event and the Model combo's After Update event:

Private Sub EnableControls()
      ' Start with controls enabled
      Me.verification.Enabled = TRUE
      Me.doorMod.Enabled = TRUE
      
       ' Then disable them according to Model
       Select Case  Model
             Case "A3 BFIST"
                    'Use Me.FieldName.Enabled = False  for any fields that need to be disabled
             Case "M2A2"
                    'Use Me.FieldName.Enabled = False  for any fields that need to be disabled
             Case Else
                    'Use Me.FieldName.Enabled = False  for any fields that need to be disabled for all other models
       End Select
End Sub

Open in new window



Private Sub Form_Current()

       EnableControls
End Sub

Open in new window

Private Sub Model_AfterUpdate()
      EnableControls
End Sub

Open in new window

Avatar of gigifarrow
gigifarrow

ASKER

Thank you, I will try it and see if it works.
ASKER CERTIFIED SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
gigifarrow,

Did you actually try the solution I posted?  Just curious what you found wrong with it.

Also - since you found a solution here, you should delete your original question.  EE does not allow duplicate questions.