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-10-14T19:28:07+00:00

    I just tried this again and it worked! The reason it wasn't working was because I was trying to put in the control name and not the name of the actual field.  Any how the person who originally created the database had the name "supervisor's name" as the name but the ' was messing me up.  Is there a way to keep the names the way they are without the coding recognizing it as something else?  what I did was take the**'**out and make it "supervisors name".

    Thanks again you guys are the best!

    Was this answer helpful?

    0 comments No comments
  2. ScottGem 68,840 Reputation points Volunteer Moderator
    2010-10-14T19:21:03+00:00

    The Enabled property of ANY control has a True/False (Yes/No, On/Off) value. The code you are using sets the Enabled property  depending on the value returned by the expression: Me.Combo_Box.ListIndex >= 0. That expression returns a True if an item is selected in the combo and a False is nothing is selected. So it would work with any control.


    Hope this helps, Scott<> P.S. Please post a response to let us know whether our answer helped or not. Microsoft Access MVP 2009 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
  3. Anonymous
    2010-10-14T19:20:00+00:00

    It's the same for any kibd of control:

       Me.thecheckbox.Enabled = (Me.Combo_Box.ListIndex >= 0)

    Isn't this the same question that you asked in your other thread?

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2010-10-14T19:13:49+00:00

    turbon5.0 wrote:

    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

    Your code should work for check boxes too.

    What's the exact problem? An error, nothing happens, ...?


    cu

    Karl

    *******

    Access-FAQ (German/Italian): http://www.donkarl.com

    Was this answer helpful?

    0 comments No comments