Disable or Grey out Check box If Combo or Text Box Not Filled In

Anonymous
2010-10-14T18:47:39+00:00

Hi,

I could get a combo box to disable text boxes using the code below, but how can I make this work if it isn't a text box and it is a check box?:

Private Sub Combo_Box_AfterUpdate()

Me.Text_Box.Enabled = (Me.Combo_Box.ListIndex >= 0)

End Sub

Thanks

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
Answer accepted by question author
Anonymous
2010-10-14T21:56:54+00:00

A few things wrong here:

1.  You cannot compare something to Null.  Nothing equals Null, not even Null.  The IsNull function is used to determine if something is Null.

2.  In any case the Enabled property is either True or False, not Null.

So:

Private Sub Text_box_AfterUpdate()

    If IsNull(Me.text_box) Then

        Me.Text_box_2.Enabled = False

    Else

        Me.Text.box_2.Enabled = True

    End If

End Sub

or more succinctly:

Private Sub Text_box_AfterUpdate()

     Me.Text.box_2.Enabled = Not IsNull(Me.text_box)

End Sub

If this is in a bound form and you want the Text.box_2 to be disabled when you move to an existing record where Text_box is Null, then also put the code in the form's Current event procedure.


Ken Sheridan, Stafford, England

Was this answer helpful?

0 comments No comments

56 additional answers

Sort by: Most helpful
  1. Anonymous
    2010-12-06T23:38:27+00:00

    Let me add to this long winded discussion...  In all these efforts, you have code all over the place doing different things.  Here is the simplified path:

    Start by creating a single Sub procedure to handle all of controls on the form.

    Private Sub ManageControls()

      Me.MyControl1.Enabled = [Validation]  (i.e. Not IsNull(Me.MyControl0) or Not IsNull(Me.MyField0), etc.)

      Me.MyControl2.Enabled = [Validation]  (i.e. Me.MyControl1.Enabled)

      And so on...

    End Sub

    for each of your controls that affects subsequent controls, add the event procedure AfterUpdate and insert the call to the above Sub Procedure.

    Private Sub MyControl1_AfterUpdate()

       ManageControls

    End Sub

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-12-06T23:02:59+00:00

    Here are the two codes that I currently have.  I need it so Follow_Up_Date can't be left blank if it is enabled.  So the user can't move on without having this field disabled or filled in.

    Private Sub Additional_Follow_Up_Required_AfterUpdate()

    If Additional_Follow_Up_Required Then

        Me.Follow_Up_Date.Enabled = True

        Follow_Up_Date.SetFocus

      Else

        Me.Follow_Up_Date.Enabled = False

        Follow_Up_Date = Null

      End If

    End Sub

    Private Sub Follow_Up_Date_AfterUpdate()

    If Not IsNull(Follow_Up_Date) Then

        Me.Follow_Up_Within_5_Business_Days.Enabled = True

      Else

        Me.Follow_Up_Within_5_Business_Days.Enabled = False

        Follow_Up_Within_5_Business_Days = Null

      End If

    End Sub

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-12-06T18:31:05+00:00

    Okay, I have another problem. Say I have field "A" enabled. When field A is enabled, I don't want the user to be able to move on without either filling this field in or unchecking the box that enabled field "A". How can I do this? Thanks

    Was this answer helpful?

    0 comments No comments
  4. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more