Disabled and Locked Textboxes

kevygee

Registered User.
Local time
Today, 04:05
Joined
Jun 7, 2005
Messages
32
I'm creating an Access form and there are three sections to the form of which the user should only fill out one. So, they are controlled by a radio group and the desired action is as follows:

There is a default choice (by far, the most common) and it will be selected when the form is opened. When the user selects one of the radio options, the section controlled by that radio option will become enabled and the other two sections will become disabled/locked.

So I found that each box (textbox, combobox, etc) has the property enabled and locked. So I just set this accordingly depending on what is selected. The actual result is that the boxes will be grayed out and become disabled, but will never become enabled again.

Here's some abbreviated code:

Code:
Private Sub accountRequestType_AfterUpdate()
    If Me.accountRequestType.Value = 1 Then
        enableSection1
        disableSection2
        disableSection3
    ElseIf Me.accountRequestType.Value = 2 Then
        disableSection1
        enableSection2
        disableSection3
    ElseIf Me.accountRequestType.Value = 3 Then
        disableSection1
        disableSection2
        enableSection3
    End If
End Sub
So an example of a disable function (which seems to work) is as follows:
Code:
Sub disableSection1()
     Me.text123.Enabled = No
     Me.text123.Locked = Yes
End Sub
And for an enable function (which doesn't seem to work):
Code:
Sub enableSection1()
     Me.text123.Enabled = Yes
     Me.text123.Locked = No
End Sub
So I'm a bit lost here, any ideas would be great. Are there different steps I need to take in order to enable them again? Am I being clear?

Thanks in advance for any ideas.
 
Code:
Private Sub accountRequestType_AfterUpdate()

    Call DisableAll

    Select Case Me.accountRequestType

        Case Is = 1
            Me.Text1.Enabled = True
            Me.Text1.Locked = False

        Case Is = 2
            Me.Text2.Enabled = True
            Me.Text2.Locked = False

        Case Is = 3
            Me.Text3.Enabled = True
            Me.Text3.Locked = False

    End Select

End Sub

Private Sub DisableAll()
    Me.Text1.Enabled = False
    Me.Text1.Locked = True
    Me.Text2.Enabled = False
    Me.Text2.Locked = True
    Me.Text3.Enabled = False
    Me.Text3.Locked = True
End Sub
 
Thank you very much for the rearrangement idea, it really shortened and cleaned up my code.

The problem that I was having was that I was using the words "yes" and "no" instead of "true" and "false." I was reading somewhere a statement about properties and the words "yes" and "no" were used. Guess they were wrong.

Moral of this thread: Use True and False keywords, not Yes and No.
 

Users who are viewing this thread

Back
Top Bottom