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. Anonymous
    2010-10-16T03:31:07+00:00

    Condition expressions are just ordinary expressions that evaluate to True or False.  There's no logical difference between A + B  and A > B or a near infinite number of ways of combining values and operators.  All the builtin functions and operators are easily found in the VBA Help - Table of Contents, most of them with examples.

    And No, I for one do not attempt to memorize this stuff, especially when all the details are just a few clicks away.  With experience, you should start to see a logical pattern to most things and kind of know what to expect even if you don't know the name of whatever helps you do something you have never done before.  Even more complex operations that may take many lines of code have a kind of logical flow.  But it does take a fair amount of study and practice.  Once you start to become comfortable doing different things and have some time on your hands, try going through the Help Table of Contents topic by topic just to get a feel for all stuff thats available.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-10-15T22:45:09+00:00

    Thanks.  I guess I didn't mean the code is different.  I meant the condition expression is different.  Thanks a bunch since I'm new to this stuff.  Anyhow, is there a place I can look at to find all these types of conditions?  Do you guys memorize all this stuff?

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-10-15T22:08:29+00:00

    They are all following the same pattern:

    Me.<controlname>.Enabled = <condition expression>

    Because you have different situations, the <condition expression> varies for each situation.  And, of course the <controlname> changes when you want to enable different controls.

    Just in case you think the third one does not follow that pattern, you could have used:

    Me.Other_field.Enabled = Check_box

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2010-10-15T20:15:27+00:00

    from the 3 codes that I used it seems that they are different from each other and not just the control names.  These are the codes that I used:

    Code for blank text box that needs to be filled or not null in order for another text box to be enabled

    Private Sub Text_box_AfterUpdate()      Me.Text.box_2.Enabled = Not IsNull(Me.text_box) End Sub


    Code for combo box that needs to be filled in order for another text box to be enabled

    Private Sub Combo_box _afterupdate()

    Me.Any_Other_Box_Event.Enabled = (Me.Combo_box.ListIndex >= 0)

    End Sub


    Code for check box that needs to be filled in order for another box to be enabled

    Private Sub Check_box_AfterUpdate()


    If Check_box Then ' if check_box is ticked

    Me.Other_field.Enabled = True

    Else

    Me.Other_field.Enabled = False

    End If

    End Sub

    Was this answer helpful?

    0 comments No comments