Disable multiple textboxes with a check box

ewan97

Registered User.
Local time
Today, 00:54
Joined
Nov 17, 2014
Messages
27
I've been trying to wrap my head around this for a while and all the solutions I've found so far only deal with one checkbox for each textbox or weren't very clear. I'm not very good with vba and my school expects us to basically become experts and create a full system and documentation in the space of 5 months.

When UseDDelivery is checked the three textboxes should be disable and when the form is opened UseDDelivery is set to be checked by default so the textboxes should be disabled when the form opens but they aren't. the two different ways of doing it are shown below.

Elements specific to my system :
UseDDelivery = checkbox
AltDeliveryAddress = textbox1
AltDeliveryTown = textbox 2
AltdeliveryPostcode = textbox3​


Solution 1:
Code:
Me.AltDeliveryAddress.Enabled = UseDDelivery.Value
Me.AltDeliveryTown.Enabled = UseDDelivery.Value
Me.AltDeliveryPostcode.Enabled = UseDDelivery.Value
This is a bit of vba a friend wrote for me quickly, it includes all three textboxes but the checkbox enables them instead of disables.

solution 2:
Code:
Private Sub UseDDelivery_AfterUpdate()
If AltDeliveryAddress.Enabled = True Then
AltDeliveryAddress.Enabled = False
Else
AltDeliveryAddress.Enabled = True
End If
End Sub
With this bit of vba I found the checkbox enables the textbox instead of disabling it and I can't figure out how to include the other two textboxes
 
From your solution 2.

Use the value of the checkbox directly as the value of the enabled property of the text boxes.

Me.AltDeliveryAddress.Enabled = Me.UseDDelivery

No need for an if/then/else routine.

Edit: this is what you had in solution 1, but remove the .value
 
This does include all the textboxes but still makes the checkbox enable the textboxes instead of disabling them, how do I 'invert' its effect, for lack of a better term?
 
This does include all the textboxes but still makes the checkbox enable the textboxes instead of disabling them, how do I 'invert' its effect, for lack of a better term?

The above works for me.

But to answer your question directly chuck in a NOT to reverse things, like so:

Code:
Me.AltDeliveryAddress.Enabled = NOT Me.UseDDelivery

Update: So what the above is saying, make .enabled TRUE when UseDDelivery is FALSE (Not True).
 
Last edited:
The NOT made it function as intended thanks
 

Users who are viewing this thread

Back
Top Bottom