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: Newest
  1. Anonymous
    2010-12-02T00:47:55+00:00

    If we're talking about the same code:

       If Nz(Who_Was_Notified_Police, False) Then

           Me.Who_Was_Notified_Police_Name.Enabled = True

         . . .

    The Enable = True lines will run when Nz(Who_Was_Notified_Police, False) is True and that will happen only when Who_Was_Notified_Police is True

    Maybe it would be clearer using a redundant comparison:

       If Nz(Who_Was_Notified_Police, False)=True Then

    The =True is unnecessary because, when Nz(Who_Was_Notified_Police, False) is True, then Nz(Who_Was_Notified_Police, False)=True will still be True

    I understand that it will run when true, it's just that I don't see it in the code that it states only when true that it will run.  Unlike the second option you gave it clearly states when = true.  Is this code just one of those that you have to know it only works when true and it's something that can't be seen?  To me it looks like it is stating if the field is null to make it say false.

    Thanks

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-11-25T01:38:30+00:00

    If we're talking about the same code:

       If Nz(Who_Was_Notified_Police, False) Then

           Me.Who_Was_Notified_Police_Name.Enabled = True

         . . .

    The Enable = True lines will run when Nz(Who_Was_Notified_Police, False) is True and that will happen only when Who_Was_Notified_Police is True

    Maybe it would be clearer using a redundant comparison:

       If Nz(Who_Was_Notified_Police, False)=True Then

    The =True is unnecessary because, when Nz(Who_Was_Notified_Police, False) is True, then Nz(Who_Was_Notified_Police, False)=True will still be True

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-11-25T00:27:06+00:00

    Thanks,  I understand the Nz(X, False) will return True if X is True.  It will return False if X is False or Null.  Remember that No, False and 0 all mean the same thing, but I don't see where it is saying that only if true to enable the specified fields.  The second procedure that you gave me clearly states to only enable when true, but I don't see where this one does this.  It works, but I just want to try to understand the statements.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2010-11-23T16:24:13+00:00

    I still have no idea how null is intruding into this situation. 

    Nz(X, False) will return True if X is True.  It will return False if X is False or Null.  Remember that No, False and 0 all mean the same thing.

    I think the confusion is because you are looking at the Format property, seeing the named format Yes/No and confusing it with the data type.  Just because the Yes/No format displays 0 as No instead of False has nothing to do with anything beyond what you see in a text box, the value is still 0.

    When you get into creating your own custom formats, you will see that you can display a Yes/No (boolean) data type value (-1/0 or True/False) just about any way you want.  For example, you could use the format specification

       "Oops";"Success";"Failure"

    to get a text box to display Success or Failure instead of Yes or No.

    Was this answer helpful?

    0 comments No comments