Active, Inactive textboxes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Scldb
    New Member
    • Feb 2007
    • 29

    Active, Inactive textboxes

    I have a form needs to be filled out. A lot of the questions are a yes/no question. When they pick yes I want some other textboxes to be active, and when they pick no I want the textboxes to be inactive. Example - A question could be: Do you have siblings. If you check yes, then other line would appear to say “How many” (other textboxes are active)? If you say no, then it skips to the next question (other textboxes are inactive - grayed out).
    How do I do this? If it includes coding, can I get help with the coding?
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    It does include coding, but at what I would say is a fairly basic level.

    Say you have a TextBox control [txtQ1] which expects either "Y" or "N". When the response "Y" is entered you want another TextBox [txtA1] to be enabled for input, but when the response "N" is entered you want TextBox [txtA1] to be disabled for input.

    The following code could then be used to cause this to happen. This is called an Event Procedure and in this case it handles the AfterUpdate event for the [txtQ1] control.
    Code:
    Private Sub txtQ1_AfterUpdate()
        Me.txtA1.Enabled = (Me.txtQ1 = "Y")
    End Sub

    Comment

    • Scldb
      New Member
      • Feb 2007
      • 29

      #3
      Originally posted by NeoPa
      It does include coding, but at what I would say is a fairly basic level.

      Say you have a TextBox control [txtQ1] which expects either "Y" or "N". When the response "Y" is entered you want another TextBox [txtA1] to be enabled for input, but when the response "N" is entered you want TextBox [txtA1] to be disabled for input.

      The following code could then be used to cause this to happen. This is called an Event Procedure and in this case it handles the AfterUpdate event for the [txtQ1] control.
      Code:
      Private Sub txtQ1_AfterUpdate()
          Me.txtA1.Enabled = (Me.txtQ1 = "Y")
      End Sub


      It does work but if I pick one record that is no, all textboxes going forward locked/grayed out. Can I have a code to reset on every new record

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        Originally posted by Scldb
        It does work but if I pick one record that is no, all textboxes going forward locked/grayed out. Can I have a code to reset on every new record
        I'm sorry I don't understand you :S

        This isn't a continuous form is it?

        Comment

        • Scldb
          New Member
          • Feb 2007
          • 29

          #5
          Originally posted by NeoPa
          I'm sorry I don't understand you :S

          This isn't a continuous form is it?
          Let's hope this will clear it up:
          Example: First question - Do you have any any siblings?
          Second question - How many
          I want the "How Many" question to be Disabled/Inactive until the first question is picked(yes).
          Here is my actual code so far:
          Code:
          Sub txtIs_AfterUpdate() 
            Me.txtApplication.Enabled = Me.txtIs 
          End Sub
          What do I need in addition to the code to make this work? Thank you for your help.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            #6
            I think you copied the code down wrong.

            Assuming the fields you've used match the correct controls, you need :
            Code:
            Sub txtIs_AfterUpdate() 
              Me.txtApplication.Enabled = (Me.txtIs = "Y")
            End Sub

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32633

              #7
              Originally posted by NeoPa
              ...
              Code:
              Sub txtIs_AfterUpdate() 
                Me.txtApplication.Enabled = (Me.txtIs = "Y")
              End Sub
              What this is saying is :
              • Every time the operator makes a selection in Me.txtIs
              • First determine if Me.txtIs is "Y" or not (in the parentheses).
              • Assign this boolean (True/False) result to Me.txtApplicati on.Enabled.

              Does that make better sense now?

              Comment

              • Scldb
                New Member
                • Feb 2007
                • 29

                #8
                Originally posted by NeoPa
                What this is saying is :
                • Every time the operator makes a selection in Me.txtIs
                • First determine if Me.txtIs is "Y" or not (in the parentheses).
                • Assign this boolean (True/False) result to Me.txtApplicati on.Enabled.

                Does that make better sense now?
                After applying this code, when I check the box - the textbox that I want to be enabaled is actually disabled (it was enable to start out which I want it disable until I check the box). Thank you for your help and hope you can still help me on this.

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32633

                  #9
                  You will probably need to provide some more info then. I'm running on air here nearly.

                  What type of control is txtIs (a TextBox I would guess)?
                  What's the exact question they are expected to answer?
                  Is the user entering "Y"? Maybe they enter "y"? Or "Yes" or something.

                  In any case, I think the code should probably change to the following so that we needn't care how they enter it :
                  Code:
                  Sub txtIs_AfterUpdate()
                    Me.txtApplication.Enabled = (UCase(Me.txtIs) = "Y")
                  End Sub

                  Comment

                  • Scldb
                    New Member
                    • Feb 2007
                    • 29

                    #10
                    Originally posted by NeoPa
                    You will probably need to provide some more info then. I'm running on air here nearly.

                    What type of control is txtIs (a TextBox I would guess)?
                    What type of control is txtIs (a TextBox I would guess)?
                    Is the user entering "Y"? Maybe they enter "y"? Or "Yes" or something.

                    In any case, I think the code should probably change to the following so that we needn't care how they enter it :
                    Code:
                    Sub txtIs_AfterUpdate()
                      Me.txtApplication.Enabled = (UCase(Me.txtIs) = "Y")
                    End Sub
                    To help you help me, here are the answers to you question:
                    What type of control is txtIs (a TextBox I would guess)? - Data type is Yes/No (so on the form all I get is a box to check)

                    What type of control is txtIs (a TextBox I would guess)? - I'm assuming that if a user checks the box this would be a "yes".

                    So txtIs is the checkbox for Yes/No and txtApplication is the next question that should only be active/enable if a user checks the txtIs checkbox. Also, I want txtApplication to be Inactive/Disabled when the user opens the form, right now it's active.

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32633

                      #11
                      Ah, it seems you are not yet aware WHY we preceed the name with things like "txt", "cbo", "bln" etc.

                      txtIs indicates that the control is a TextBox. For a Yes/No field you should use "bln" instead. Thus the control should be named [blnIs].

                      This explains why the code didn't work. The code was directed at a TextBox control.
                      Originally posted by Scldb
                      ...
                      What type of control is txtIs (a TextBox I would guess)? - I'm assuming that if a user checks the box this would be a "yes".
                      ...
                      No! Most emphatically not.
                      Most can only return values of True or False (NB. Not strings "True" and "False", but boolean values which have numerical equivalents of -1 & 0 respectively).
                      Originally posted by Scldb
                      ...
                      Also, I want txtApplication to be Inactive/Disabled when the user opens the form, right now it's active.
                      ...
                      I thought I'd already said to set this to Enabled=No in the design, but I checked the thread and it's not there anywhere - Ooops. That's what you need to do anyway.

                      Try this new code for your boolean (Yes/No) field (NB. The control should be renamed first to indicate the type) :
                      Code:
                      Sub blnIs_AfterUpdate()
                        Me.txtApplication.Enabled = Me.blnIs
                      End Sub

                      Comment

                      • Scldb
                        New Member
                        • Feb 2007
                        • 29

                        #12
                        Thank very very much. It works.

                        Comment

                        • NeoPa
                          Recognized Expert Moderator MVP
                          • Oct 2006
                          • 32633

                          #13
                          Very pleased to hear it and you're welcome :)

                          Comment

                          • Scldb
                            New Member
                            • Feb 2007
                            • 29

                            #14
                            Originally posted by NeoPa
                            Very pleased to hear it and you're welcome :)
                            Now I got another question related to this. The code that you gave me works but if I check yes (blnIS) for the active record that I'm on and then when I'm finished filling out the form and move on to the next form - the txtApplication is already active. It's suppose to be inactive/deactivated until the user checks yes (checks the blnIS checkbox).

                            The code that I'm using is:
                            Code:
                            Sub blnIs_AfterUpdate()
                              Me.txtApplication.Enabled = Me.blnIS
                            End Sub
                            What additional code do I need.
                            Last edited by NeoPa; Aug 12 '08, 04:59 PM. Reason: Please use the [CODE] tags provided

                            Comment

                            • NeoPa
                              Recognized Expert Moderator MVP
                              • Oct 2006
                              • 32633

                              #15
                              You need similar code in your Form_OnActive() event procedure.

                              Comment

                              Working...