turn a control on, then off, on a form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ndeeley
    New Member
    • Mar 2007
    • 139

    turn a control on, then off, on a form

    Hi there,

    I have a button (cmdShowSearchB uttons) on a form which, when clicked, makes two input boxes and two search buttons visible (ie `on`) - through the usual means of a click event.

    However I want the button (cmdShowSearchB uttons) to make these controls not visible when clicked again (ie 'off'). I'm sure I can do this through use of IF statements, but by golly, I can't get it to work...

    Anyone who can point me in the right direction would be appreciated!

    Thanks
    Neil
  • Scott Price
    Recognized Expert Top Contributor
    • Jul 2007
    • 1384

    #2
    Posting your current code will help us out a bit!

    The general idea is that you will use the If ... Then structure to first of all test whether the control is Visible. If [Control].Visible = False Then... Make it visible, otherwise make it invisible.

    Regards,
    Scott

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      Set the textboxes to Visible = No in the Property sheet.

      In the cmdShowSearchBu ttons's Property Box, under the Caption Property type in Show Textboxes. Behind the Button's OnClick event, using the place this:

      Code:
      Private Sub cmdShowSearchButtons_Click()
        If cmdShowSearchButtons.Caption =  "Show Textboxes" Then
      	cmdShowSearchButtons.Caption = "Hide Textboxes"
      	Me.YourTextboxNameHere.Visible = True
        Else
      	cmdShowSearchButtons.Caption = "Show Textboxes"
      	AnyOtherControl.SetFocus
      	Me.YourTextboxNameHere.Visible = False
        End If
      End Sub
      I think I got this adapted right for your app. You just need to add all the textboxes/buttons you need to control in the same manner. If you have a problem let us know.

      Because you can't hide a textbox that has focus, you need to use Line # 7 to move the focus to a control other than the ones you're hiding, to prevent an error from popping up.

      Linq ;0)>

      Comment

      • ndeeley
        New Member
        • Mar 2007
        • 139

        #4
        Originally posted by missinglinq
        Set the textboxes to Visible = No in the Property sheet.

        In the cmdShowSearchBu ttons's Property Box, under the Caption Property type in Show Textboxes. Behind the Button's OnClick event, using the place this:

        Code:
        Private Sub cmdShowSearchButtons_Click()
          If cmdShowSearchButtons.Caption =  "Show Textboxes" Then
        	cmdShowSearchButtons.Caption = "Hide Textboxes"
        	Me.YourTextboxNameHere.Visible = True
          Else
        	cmdShowSearchButtons.Caption = "Show Textboxes"
        	AnyOtherControl.SetFocus
        	Me.YourTextboxNameHere.Visible = False
          End If
        End Sub
        I think I got this adapted right for your app. You just need to add all the textboxes/buttons you need to control in the same manner. If you have a problem let us know.

        Because you can't hide a textbox that has focus, you need to use Line # 7 to move the focus to a control other than the ones you're hiding, to prevent an error from popping up.

        Linq ;0)>

        Worked like a charm!
        Thanks Both!
        Neil

        Comment

        • Scott Price
          Recognized Expert Top Contributor
          • Jul 2007
          • 1384

          #5
          Glad it works for you! Happy to help :-)

          Regards,
          Scott

          Comment

          • Jerry911
            New Member
            • Nov 2007
            • 10

            #6
            I have a very similiar situation with a form, is it appropriate to post it here or start a new thread? It involves hiding/unhiding fields based on the selection of a value (case) from a list box.

            Comment

            • missinglinq
              Recognized Expert Specialist
              • Nov 2006
              • 3533

              #7
              You never go wrong starting your own thread!

              Welcome to TheScripts!

              Linq ;0)>

              Comment

              Working...