VBA - Showing / Hiding Textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • daoxx
    New Member
    • Mar 2008
    • 32

    VBA - Showing / Hiding Textbox

    Hello
    I've searched, posted and solved this (Thanks for helping!), but now it came back to bite me in the *ss.

    I have a Yes/No field that is represented by a check box in my form1.
    I want to show another field (textbox) when the mouse pointer goes over the checkbox, and make it not visible when the mouse moves away from it.

    My problem is that when I make the textbox diseappear, if the user set focus on it and moves the mouse away, Access gives me a "Can't hide a control while it has focus" error.

    My question is: How can I resolve this problem?

    I later added this: text2.SetFocus

    I need to set focus on something else, but I can't do with the "when mouse moves on top of the form's background" thing, because then whenever the user moved the mouse on the background, the focus would be set to the same thing, i.e. user types in something to text1 (show/hide textbox) and then wants to change text3 (visible), but can't move the mouse because the focus would be set to text2.

    This is the code I used:

    Code:
    Private Sub Chck1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    text1.Visible = True
    End Sub
    
    Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    text1.Visible = False
    End Sub
    I will appreciate any help possible,
    Thank you
    Last edited by daoxx; Mar 31 '08, 03:51 PM. Reason: lostfocus
  • JConsulting
    Recognized Expert Contributor
    • Apr 2007
    • 603

    #2
    Originally posted by daoxx
    Hello
    I've searched, posted and solved this (Thanks for helping!), but now it came back to bite me in the *ss.

    I have a Yes/No field that is represented by a check box in my form1.
    I want to show another field (textbox) when the mouse pointer goes over the checkbox, and make it not visible when the mouse moves away from it.

    My problem is that when I make the textbox diseappear, if the user set focus on it and moves the mouse away, Access gives me a "Can't hide a control while it has focus" error.

    My question is: How can I resolve this problem?

    I later added this: text2.SetFocus

    I need to set focus on something else, but I can't do with the "when mouse moves on top of the form's background" thing, because then whenever the user moved the mouse on the background, the focus would be set to the same thing, i.e. user types in something to text1 (show/hide textbox) and then wants to change text3 (visible), but can't move the mouse because the focus would be set to text2.

    This is the code I used:

    Code:
    Private Sub Chck1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    text1.Visible = True
    End Sub
    
    Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    text1.Visible = False
    End Sub
    I will appreciate any help possible,
    Thank you
    Outside the box...

    create an unbound textbox or just a box that matches your background and large enough to cover up the Textbox in question. Make IT visible or invisible on top of your Textbox to "hide" it.

    Comment

    • daoxx
      New Member
      • Mar 2008
      • 32

      #3
      What if the textboxes that I need to hide are partially stacked? The boxes would either cover more than necessary, or show more than necessary.

      Comment

      • mshmyob
        Recognized Expert Contributor
        • Jan 2008
        • 903

        #4
        I may be missing something here because I don't know what you mean about the 'form background' thing.

        But assuming you have a checkbox (chkControlName ) and say 2 text boxes on the form (txtName1 and txtName2). When mouse moves over checkbox it will display txtName1. After losing focus on txtName1 it will setfocus to txtName2 and hide txtName 1 again.

        In the MouseMove event of chkControlName
        [code=vb]
        Me.txtName1.Vis ible = True
        [/code]


        In the LostFocus event of txtName1
        [code=vb]
        Me.txtName2.Set Focus
        Me.txtName1.Vis ible = False
        [/code]


        Does this help?

        cheers,

        Originally posted by daoxx
        Hello
        I've searched, posted and solved this (Thanks for helping!), but now it came back to bite me in the *ss.

        I have a Yes/No field that is represented by a check box in my form1.
        I want to show another field (textbox) when the mouse pointer goes over the checkbox, and make it not visible when the mouse moves away from it.

        My problem is that when I make the textbox diseappear, if the user set focus on it and moves the mouse away, Access gives me a "Can't hide a control while it has focus" error.

        My question is: How can I resolve this problem?

        I later added this: text2.SetFocus

        I need to set focus on something else, but I can't do with the "when mouse moves on top of the form's background" thing, because then whenever the user moved the mouse on the background, the focus would be set to the same thing, i.e. user types in something to text1 (show/hide textbox) and then wants to change text3 (visible), but can't move the mouse because the focus would be set to text2.

        This is the code I used:

        Code:
        Private Sub Chck1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        text1.Visible = True
        End Sub
        
        Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        text1.Visible = False
        End Sub
        I will appreciate any help possible,
        Thank you

        Comment

        • daoxx
          New Member
          • Mar 2008
          • 32

          #5
          By "form background" I meant the part named "Detail", sorry :P

          Yea, I was missing the LostFocus thingie.. Thanks.
          Only problem now is that if the user passes the mouse pointer over the checkbox, the textbox1 will pop-up and not go away until the user clicks it (set focus on it) and then clicks some other textbox.

          Is there anyway to control this? Perhaps a timer that does a condition where if the user does not set focus on the textbox1 after some time, it will disappear?
          (I've no idea if you can do that)

          Thanks for helping

          Comment

          • mshmyob
            Recognized Expert Contributor
            • Jan 2008
            • 903

            #6
            Yes you can do that. You can setfocus to text1 if you want after moving the mouse over the checkbox (don't know if you want that though).

            I will do the timer thing later today for you , I have to go see a client right now.

            cheers,

            Originally posted by daoxx
            By "form background" I meant the part named "Detail", sorry :P

            Yea, I was missing the LostFocus thingie.. Thanks.
            Only problem now is that if the user passes the mouse pointer over the checkbox, the textbox1 will pop-up and not go away until the user clicks it (set focus on it) and then clicks some other textbox.

            Is there anyway to control this? Perhaps a timer that does a condition where if the user does not set focus on the textbox1 after some time, it will disappear?
            (I've no idea if you can do that)

            Thanks for helping

            Comment

            • daoxx
              New Member
              • Mar 2008
              • 32

              #7
              Thanks! Seriously, thank you :D
              It'll help me alot.

              Originally posted by mshmyob
              Yes you can do that. You can setfocus to text1 if you want after moving the mouse over the checkbox (don't know if you want that though).

              I will do the timer thing later today for you , I have to go see a client right now.

              cheers,

              Comment

              • mshmyob
                Recognized Expert Contributor
                • Jan 2008
                • 903

                #8
                Ok same scenario as before but I added a timer event. When you move over the check box TEXT1 will display for a set period of time if it does not have focus. If it has focus it will stay displayed. When you move off of it it will disappear again.

                This goes in the MouseMove event of the check box
                [code=vb]
                ' show your text box if mouse moves over the checkbox
                Me.Text1.Visibl e = True
                'start the timer event for a specified amount of time (increase for more time)
                Me.Form.TimerIn terval = 2000
                [/code]

                This goes in the OnTimer event of the Form
                [code=vb]
                ' determine if we are in the text box
                ' if so do nothing until we lose focus
                If Me.ActiveContro l.name = "Text1" Then
                'do nothing
                Else
                Me.Text1.Visibl e = False
                Me.Form.TimerIn terval = 0
                End If
                [/code]

                Remove everything from the LostFocus event of Text1 (as from the previous code example)

                cheers,


                Originally posted by daoxx
                Thanks! Seriously, thank you :D
                It'll help me alot.

                Comment

                • daoxx
                  New Member
                  • Mar 2008
                  • 32

                  #9
                  Thank you so much!
                  Although I don't have the possibility to test it right now, I'll say something when I can.

                  Thanks

                  Comment

                  • daoxx
                    New Member
                    • Mar 2008
                    • 32

                    #10
                    Yes, it works perfectly! Thank you :)
                    If only I could give you some kind of expert points :d

                    Thanks

                    Comment

                    • mshmyob
                      Recognized Expert Contributor
                      • Jan 2008
                      • 903

                      #11
                      You're welcome. Being able to help is good enough for me.

                      cheers,

                      Originally posted by daoxx
                      Yes, it works perfectly! Thank you :)
                      If only I could give you some kind of expert points :d

                      Thanks

                      Comment

                      Working...