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
    2015-05-27T19:37:32+00:00

    Hi turbon5.0,

    Hopefully you have found a solution by now, but if not something like this should work.

    If something.value="yes" then

    anothertextbox.value<>""

    if anothertextbox.value=""then

    msgbox ("Error Message", "Title")

    End if

    End if

    Was this answer helpful?

    0 comments No comments
  2. 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

  3. Anonymous
    2010-12-07T00:59:20+00:00

    How can I make it so if something = "yes" that another text box can't be null otherwise a message pops up and won't allow you to continue until this is fixed?

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2010-12-06T23:52:50+00:00

    A word on check boxes.  They have three possible states True, False, Null.  To avoid problems that seem to be occurring here, begin by setting the default field value in the table to False.  You might also want to do the same for the check box on the form.  Once you have set the table's default value, create an update query to update all true/false fields to False where field=null.

    Was this answer helpful?

    0 comments No comments