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: Oldest
  1. Anonymous
    2010-11-19T01:02:35+00:00

    The code looks fine to me.  I don't see anything in there where a Null value could cause a problem.  The only thought that comes to mind is if you misspelled a name.

    If the problem is an invalid name, it would imply that the module does not have the line:

      Option Explicit

    at the top, above all other code.  If that is not in the module, add it.  Then use the Debug - Compile menu item to compile the code.  If there is a bad name or syntax error, the compiler will stop and highlight the line with the error,

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-11-19T01:16:32+00:00

    the line that it highlighted was the

    Private Sub Frame28_AfterUpdate()

    Somehow I got the code to work by adding the not to the code like this, but this didn't work for another field that is a yes no checkbox because it would keep the second field always enabled:

    Private Sub Frame28_AfterUpdate()

    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

    Here is the second code that didn't work (note that I had to also switch around the false and the true statement too in order to enable when checked and disable when not checked. If not it enabled when not checked and disabled when checked)  If I used this code it would keep the who_was_notified_police_name field enabled automatically when going to a new record:

    Private Sub Who_Was_Notified_Police_AfterUpdate()

        if who_was_notified_police then

           me.who_was_notified_police_name.enabled = false 

           me.who_was_notified_police_name.enabled=true

       end if

    end sub

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-11-19T01:51:56+00:00

    As a reply to my previous post, I think this whole thing was getting messed up because my yes/no check box didn't have a default value.  I actually wanted it to not have one so I could see when they forgot to do it, but since I placed "no" as the default value, the following code now works properly without giving the invalid null error:

    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

    Does is there a way to have this all work without a default value?

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2010-11-19T03:28:40+00:00

    While specifying a default value for Frame28 will prevent it from being Null, there must be more to this.  It also implies that Frame28 is not bound to a Yes/No field, because Yes/No fields automatically default to False.

    All that brings into question the type of the field (in its table) bound to the Frame28 control.  Since Frame28 is an odd name for a check box, I have to also ask what it really is and what possible values it can have.

    Was this answer helpful?

    0 comments No comments