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. 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

  2. Anonymous
    2010-11-22T20:19:18+00:00

    When I referred to field type I meant data type.  On the fields that are yes/no fields, is the fields that says default value, I wanted to leave it blank.  This is where I placed "no" to make the codes above work.  Before, it was blank.  When it was blank, the codes would give the invalid use of null error.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-11-22T19:33:29+00:00

    Be sure to make a clear distinction between controls on the form and fields in the table.  For example, do not use the word field when you are talking about a control.  You keep saying that the Yes/No field must have a default value but Yes/No field's in the table do not need a default value because they can never be null.  With a problem like this one, the whole discussion can go out the window when the two words field and control are used interchangably.

    List each field that you are testing to decide if a control should be enabled or not.  Provide the field'sDataType (Number, Text, Yes/No, etc) in the table next to the field name.  Next to that provide the range of values the field might have.

    We do not care about the controls that you want to enable/disable.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2010-11-22T18:33:11+00:00

    All the fields below are just basic text and date fields fields that are enabled/disabled depending on if frame28 is checked or not.  As for the the second procedure it is just a yes/no check box that enables/disables a text field based on if the box is checked or not.  The code that I have below didn't work with the yes no field if I didn't specify no as the default value as I got the invalid use of null error.  Is there a way to have the field perform the same without specifying a default value?

    If not Frame28 Then ' if frame28 is ticked

        Me.Participant_Last_Name.Enabled = True

        Me.Participant_First_Name.Enabled = True

        Me.Birth_Date.Enabled = True

        Me.Unit_No.Enabled = True

        Me.Provider_Name.Enabled = True

        Me.Island.Enabled = True

        Me.Contact_Person.Enabled = True

        Me.Telephone_No.Enabled = True

        Me.Fax_No.Enabled = True

        Me.Relationship.Enabled = True

        Me.Supervisor_Name_Designated_Rep_Title.Enabled = True

      Else

        Me.Participant_Last_Name.Enabled = False

        Me.Participant_First_Name.Enabled = False

        Me.Birth_Date.Enabled = False

        Me.Unit_No.Enabled = False

        Me.Provider_Name.Enabled = False

        Me.Island.Enabled = False

        Me.Contact_Person.Enabled = False

        Me.Telephone_No.Enabled = False

        Me.Fax_No.Enabled = False

        Me.Relationship.Enabled = False

        Me.Supervisor_Name_Designated_Rep_Title.Enabled = False

      End If

    End Sub

    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

    THANKS

    Was this answer helpful?

    0 comments No comments