Enable/Disable txtboxes

RexesOperator

Registered User.
Local time
Today, 10:25
Joined
Jul 15, 2006
Messages
604
I'm trying to enable/disable text boxes in a subform with a command button on the subform. The initial condition is Disabled. Thus one click should enable the textbox and the next click should disable it.

I used this format for the code from an earlier post of mine:

If Forms!frmTrxns.ctlTrxnSub.Form.txtJANDRY2pt5PerCent.Enabled = False Then
Forms!frmTrxns.ctlTrxnSub.Form.txtJANDRY2pt5PerCent.Enabled = True
Else
Forms!frmTrxns.ctlTrxnSub.Form.txtJANDRY2pt5PerCent.Enabled = False
End If

(there are no spaces in PerCent - that's a forum thing)

With the initial condition Disabled, one click will enable the fields, but the next click won't disable them again. And vice versa - enabled fields will be disabled with one click, but I can't enable them with the second click.

Do I have to build a separate procedure to redisable/reenable the fields?
 
If the control is disabled (or .Enabled = False), it will not fire an OnClick event, so your code will not work.

Also - to disable it, you'd need to set the focus to another control that is enabled.

You'll need some other condition other than it's current state to enable / disable it.

Regards,
Pete
 
I was gradually beginning to realize that. Thanks. I will work on this some more.
 
I've solved it with a bit of a kludge - I have an invisible unbound text box that I use to change focus. Is there another more elegant way of doing this?
 
With the initial condition Disabled, one click will enable the fields, but the next click won't disable them again. And vice versa - enabled fields will be disabled with one click, but I can't enable them with the second click.
You have to save the record before you can enable or disable the same control. If you added a

If Me.Dirty Then Me.Dirty = False

line to the click code before you try to set the enabled property then you should see it work.
 
As ever Bob - Brilliant. I now works without the kludge - and makes it easier to document.

Thanks once again.
 

Users who are viewing this thread

Back
Top Bottom