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-20T23:04:03+00:00

    You must be misinterpreting something somewhere.  When you describe a field in a table it's DataType is really important.  Yes/No fields (not to be confused with a control) can not be null (unless you retrieving them via an outer join query with another table). and they automatically have False until you change them to True.

    You said the Frame control is an Option Group so it's value must be an integer (not Text), probably 1 or 2 (or Null if one of the options has never been selected).

    Everything seemed simple with real Yes/No fields, but now that we know they are some other Data Type, it's not so simple.  Before we proceed, please explain each field's Data Type in the table.  This can/will affect how the code is written so trying to fix the code without knowing the Data Type would just lead to a lot of guessing.  We also need to know what you want to happen for each possible value each field might have.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-11-20T20:35:24+00:00

    Thanks. So how would I code this if I didn't want a default value? All the codes I have above require the yes no fields to not be null ot else it errors out.

    Was this answer helpful?

    0 comments No comments
  3. ScottGem 68,840 Reputation points Volunteer Moderator
    2010-11-19T13:21:00+00:00

    Frame28 is the name that Access assigned to this field in the form.  It is actually an option group box with the options of waiver and non-waiver. I didn't know any other way to make it so if you select one, it would deselect the other. The waiver/non-waiver data is stored in one column, which is a text field.  I didn't specify a default value for the frame28 field and only placed the not in the code (don't know how this worked but I just tried it).  As for the other boxes, how does the yes/no fields work with all these codes by specifying the default value?  How would I code all of this if I didn't want any default value?  It seems these codes error out with that "runtime error 94 invalid use of null"?

    Thanks

    I'm going to jump in here. First, while Access does assign a default name to each control, that doesn't mean you have to accept it. You will make your job easier if you give your controls meaningful names (like optWaiver for this control). Second, if you are using the After Update event of a control to enable or disable a set of controls and you want to repeat that action when BROWSING through records you have to repeat the code in the Form's On Current event. Think of it this way. The code in the After Update event ONLY trigers when you change the value of the Option group. So when you move to a record, that record has the default values for the Enabled property of all those controls. An alternative to repeating the code would be to add a procedure in the Form's module like so:

    Sub SetWaiver()

    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

    then in the After update event of the group AND the On Current event of the form put:

    Call SetWaiver()


    Hope this helps, Scott<> P.S. Please post a response to let us know whether our answer helped or not. Microsoft Access MVP 2010 Blog: http://scottgem.spaces.live.com/blog Author: Microsoft Office Access 2007 VBA Technical Editor for: Special Edition Using Microsoft Access 2007 and Access 2007 Forms, Reports and Queries

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2010-11-19T10:15:37+00:00

    Frame28 is the name that Access assigned to this field in the form.  It is actually an option group box with the options of waiver and non-waiver. I didn't know any other way to make it so if you select one, it would deselect the other. The waiver/non-waiver data is stored in one column, which is a text field.  I didn't specify a default value for the frame28 field and only placed the not in the code (don't know how this worked but I just tried it).  As for the other boxes, how does the yes/no fields work with all these codes by specifying the default value?  How would I code all of this if I didn't want any default value?  It seems these codes error out with that "runtime error 94 invalid use of null"?

    Thanks

    Was this answer helpful?

    0 comments No comments