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-11-23T00:10:55+00:00

    I wanted to use this procedure, but it only works when you have a default value because it won't accept null.  So I want it to enable when checks yes and disable if null or not checked.  So I think I have to actually specify using = -1 or have a default value.  Do you know how I can uncheck or clear entered texts if a box is disabled.  For example if the procedure below, if Who_Was_Notified_Police_Name is enabled and data is entered, but someone unchecks Who_Was_Notified_Police, the data is still showing in Who_Was_Notified_Police_Name.

    Private Sub Who_Was_Notified_Police_AfterUpdate()

    If Who_Was_Notified_Police Then

        Me.Who_Was_Notified_Police_Name.Enabled = True

      Else

        Me.Who_Was_Notified_Police_Name.Enabled = False

      End If

    End Sub

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-11-22T21:34:47+00:00

    You want either 1 or 2 to enable the other controls, then, because those are the only two possible values, you can test if there is any value in the field (i.e. neither option has beend selected) by using:

       If Not IsNull(Frame28) Then

    If the Who_Was_Notified_Police check box is bound to a Yes/No field, then I don't see why that procedure does not do what you want.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-11-22T21:03:13+00:00

    The Who_Was_Notified_Police control is a yes/no field like the one that I have shown in my picture.  As for the frame28 field, I didn't want things enabled for this control if you select 2, I wanted it to enable as long as 1 or 2 is selected.  Only for the Who_Was_Notified_Police control did I want the yes to enable and the no to disable other controls.  For both situations, I wanted didn't want to have to specify a default value like I did in the picture above. Just to see if would work, I tried your code above (If Frame28 = 2 Then) and it still worked without having to change the field to a number.  Sorry for so much confusion.  If I also wanted boxes to be null if they are disabled how would I do this?  This is to make sure that someone doesn't enable a field check things off and then uncheck the box that enables those fields.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2010-11-22T20:56:55+00:00

    You do not indicate (or include) the field used in the Who_Was_Notified_Police control so I can not comments on that procedure.

    The Current event code is using the Frame28 option group control (not a check box or option), which I presume is bound to the ParticipantType field.  If that's correct, the field's type must be DataType Number with Size either Integer or Long, not Text.  After you fix that, the procedure should use:

    If Frame28 = 2 Then

       Me.Participant_Last_Name.Enabled = True

        . . .

    Was this answer helpful?

    0 comments No comments