Solved How to cause a checkbox to become enabled when another checkbox is checked? (1 Viewer)

Sampoline

Member
Local time
Tomorrow, 04:23
Joined
Oct 19, 2020
Messages
161
I have a list of items that have a range of checkboxes to be checked.

1608599927213.png


I have two specific checkboxes; 'Required' and 'Completed'. I need the 'Required' checkbox to enable only once the Completed checkbox has been ticked/checked.

That is, I need one of the checkboxes to stay disabled until another specific checkbox is checked true.

The list and checkboxes are in a subform. I set the Enabled property of the 'Required' checkboxes to "No". And then I tried using an After_Update event in 'Completed' checkbox to do this:

Code:
Private Sub Completed_AfterUpdate()

If Me.chckbxCompleted = True Then
    Me.chckbxRequired.Enabled = True
Else
    Me.chckbxRequired.Enabled = False
End If

End Sub

But this didn't work. They didn't enable once I checked the 'Completed' checkbox.

Any suggestions?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:23
Joined
May 7, 2009
Messages
19,169
use the Textboxname, not the Fieldname
Code:
Private Sub chckbxCompleted_BeforeUpdate(Cancel As Integer)
Me.chckbxRequired.Enabled = Me.chckbxCompleted
End Sub
 

Sampoline

Member
Local time
Tomorrow, 04:23
Joined
Oct 19, 2020
Messages
161
use the Textboxname, not the Fieldname
Code:
Private Sub chckbxCompleted_BeforeUpdate(Cancel As Integer)
Me.chckbxRequired.Enabled = Me.chckbxCompleted
End Sub
Is there a way to do it for each item. So in my example it was 'Fruit'.

So when Apple has no tick on the 'Completed' checkbox, then the 'Required' checkbox stays disabled. But if it is ticked, then it will enable.

But this should pertain to only that particular fruit. So the next line is Orange right? I want that to be independent. And so on and so forth. If that makes sense?

Because at the moment, if I tick the checkbox for one "Completed" item, then all the 'Required' checkboxes becomes enabled. I just want that one fruit/item to enable.

Also I didn't quite understand what was meant by textboxname and fieldname? If you can clarify that for me thanks.
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 04:23
Joined
Jan 20, 2009
Messages
12,849
Code won't work with ContinuousForms as all records will all be affected. You would have to use ConditionalFormatting.

However Checkboxes don't support ConditionalFormatting so need to be simulated with a textbox.
 

Sampoline

Member
Local time
Tomorrow, 04:23
Joined
Oct 19, 2020
Messages
161
Code won't work with ContinuousForms as all records will all be affected. You would have to use ConditionalFormatting.

However Checkboxes don't support ConditionalFormatting so need to be simulated with a textbox.
My form is a single form, will that be affected too? And how do I go about simulating the conditionalformatting with a textbox.. sorry I'm not too familiar with that process.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:23
Joined
May 7, 2009
Messages
19,169
maybe change your Yes/No fields to Short Text, so you can use the Conditional Formatting.
 

Attachments

  • Frutus.accdb
    512 KB · Views: 467

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 04:23
Joined
Jan 20, 2009
Messages
12,849
The subform is Continuous.
Simulating a checkbox with a textbox is quite involved.

Have a look at this thread.

BTW I never got around to completing the Class version I mentioned in that thread.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:23
Joined
May 7, 2009
Messages
19,169
why not just add a code to the On Current Event of the Required Textbox.
see Fruit2 form.
 

Attachments

  • Frutus.accdb
    520 KB · Views: 523

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:23
Joined
Feb 19, 2002
Messages
42,971
What you are seeing is the effect of a continuous form. Each row is an instance of the subform. However, Access maintains only a single set of attributes. It doesn't maintain a separate set for each copy of the form. That is why you are seeing the checkboxes toggle in sync. This is a visual issue but not one that affects functionality if you do it correctly.

There are two places you need to toggle the property.
1. In the form's current event
2. In the AfterUpdate event of the first checkbox

You can write a common piece of code (my choice) and call it from both places. The setting for the second combo will be accurate for the CURRENT record. Since no other record can be updated, there is no need to worry. If you click the "enabled" checkbox of a different row where the checkbox should not be enabled, it will toggle to not enabled because clicking on it runs the form' Current event and the Current event toggles the setting for an existing record.

Try it.

You may be unhappy about how it looks but it should work once you do what I suggested and run the toggle code in TWO places.

To fix it, you are going to have to change the subform from DS view to Continuous. Then you can use conditional formatting to hide/show the second control which might be more visually appealing.
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 04:23
Joined
Jan 20, 2009
Messages
12,849
you are going to have to change the subform from DS view to Continuous. Then you can use conditional formatting to hide/show the second control which might be more visually appealing.
ConditionalFormatting can be used to Enable or Disable a textbox but I don't know any way to change the visibility with ConditionalFormatting in the versions of Access I have used. It isn't available for checkboxes which is why I suggested the simulated checkbox using a textbox control.

ConditionalFormatting works in a datasheet view the same as it does in ContinuousForms.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:23
Joined
Feb 19, 2002
Messages
42,971
I was thinking about text boxes. You can hide them using color but I guess you can't hide checkboxes. Although, you might be able to use stacked controls to hide a checkbox.
 

Sampoline

Member
Local time
Tomorrow, 04:23
Joined
Oct 19, 2020
Messages
161
why not just add a code to the On Current Event of the Required Textbox.
see Fruit2 form.
Hi Arnel,

Thanks for the suggestion and attached form as example. Using the GotFocus event does work for me.

Cheers for that.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:23
Joined
May 7, 2009
Messages
19,169

Users who are viewing this thread

Top Bottom