How do I make the subform the active control when the mouse moves over it?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    How do I make the subform the active control when the mouse moves over it?

    I've got a form that has a subform on it. Currently, in order to scroll in the subfomr with the mouse wheel, I have to click somewhere in the subform. I would like to be able to be able to have it be selected when the mouse moves over it so that I don't have to click. I've looked at the subform events, but the only two listed are On_Enter and On_Exit. I tried looking at the events of the subform as a form and not as a subform and the only one that makes sense is On_Mouse_Move. The only problem is that I don't know how to check if the mouse is moving over the subform or the regular form.

    Is this possible?
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Try the MouseMove() Event in the Detail Section of the SubForm.
    Last edited by NeoPa; Feb 8 '12, 09:58 PM. Reason: Removed unnecessary quote

    Comment

    • Seth Schrock
      Recognized Expert Specialist
      • Dec 2010
      • 2965

      #3
      Okay, I put the following in the MouseMove() event like you said.
      Code:
      Me.Parent![Returned Mail Subform].SetFocus
      The only problem is that as long as the mouse is over the detail section (it doesn't have to be moving), it keeps running over and over. Is there a way to keep it from getting triggered when the mouse isn't moving?

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32636

        #4
        I find your explanation very confusing Seth. Can you post the code (including all relevant lines, such as the procedure wrappers, etc).

        Comment

        • Mihail
          Contributor
          • Apr 2011
          • 759

          #5
          Define a boolean variable at the module level
          Code:
          Dim SubFormHasFocus As Boolean
          Set it to TRUE after the sub-form recive focus and run your code only if this variable is FALSE.
          When the sub-form lose focus set the variable to FALSE.

          Comment

          • Seth Schrock
            Recognized Expert Specialist
            • Dec 2010
            • 2965

            #6
            I didn't get a chance to work on it today. I'll post more tomorrow.

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32636

              #7
              No worries Seth. I'm out most of tomorrow but I'll catch up when I'm around certainly.

              Comment

              • Seth Schrock
                Recognized Expert Specialist
                • Dec 2010
                • 2965

                #8
                @NeoPa, Here is the code. It is in the subform's Detail on mouse move event.

                Code:
                Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
                Me.Parent![Returned Mail Subform].SetFocus
                End Sub
                @Mihail, Here is the code that I tried per your idea:
                Code:
                Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
                Dim SubFormHasFocus As Boolean
                
                If SubFormHasFocus = False Then
                    Me.Parent![Returned Mail Subform].SetFocus
                End If
                
                SubFormHasFocus = True
                
                End Sub
                However, the screen keeps cycling whenever the the mouse is over the detail section. If I put my mouse over a control, it stops. I'm also concerned about performance since this is the main screen used. This code will be run over and over even if we get the SetFocus problem fixed. Is there an event that runs when the mouse first moves over the subform instead of it running all the time the mouse is over the subform?

                Comment

                • ADezii
                  Recognized Expert Expert
                  • Apr 2006
                  • 8834

                  #9
                  Instead of a BOOLEAN, try a Counter (LONG). Increment the Counter by +1 whenever the Mouse moves acccross the Detail Section of the Sub-Form. Only set the Focus to the Sub-Form when the Value of the Counter = 1, then Reset the Counter to 0 when the Mouse moves to the Main Form.

                  Comment

                  • Mihail
                    Contributor
                    • Apr 2011
                    • 759

                    #10
                    @ADezii
                    Correct me, please if I am wrong.
                    I think that in boolean logic your counter act the same way as a boolean variable: Your counter IS or IS_NOT = 1.

                    @Seth
                    Your code can't work (either if you use a boolean variable or a counter one) because you initialize SubFormHasFocus inside the event procedure (line 2). And the default value is FALSE.
                    So, the IF statement will be executed every time your mouse is moving.
                    Line 8 has no effect. You can remove it :). That because when you exit from procedure (line 10) all variables declared inside the procedure using Dim statement are complete removed from memory.
                    If you wish to keep a value for a variable between calling you must use the Static statement. Simple replace DIM with STATIC.

                    In my first post I say to define the boolean variable at MODULE level.
                    Also your line 8 must be moved between line 5 and 6.

                    Any way, I prepare an example (see attachment) with a possible approach to solve your original question:
                    How do I make the subform the active control when the mouse moves over it?

                    Hope this is a help for you.
                    Good luck !
                    Attached Files

                    Comment

                    • Seth Schrock
                      Recognized Expert Specialist
                      • Dec 2010
                      • 2965

                      #11
                      That is exactly what I need.

                      I totally missed the at module level. I'll admit, I'm not very good with VBA. I have a book that would teach me if I read it, but I just don't have the time:) I've learned a lot through this forum, but I wish I new more. I'm basically learning the stuff that I need and then I print out the code so that I can use it next time with the proper adjustments.

                      Comment

                      • Seth Schrock
                        Recognized Expert Specialist
                        • Dec 2010
                        • 2965

                        #12
                        I just put the label around my subform and did the OnMouseMove event. What I don't get is that on my database, when my mouse is over the label, the code is constantly running even when the mouse is not moving. In your sample it doesn't run unless the mouse is moving and only once every half inch of movement. Any ideas? I'm using Access 2010.

                        Comment

                        • Mihail
                          Contributor
                          • Apr 2011
                          • 759

                          #13
                          And where is the problem ? Hope you had removing the BEEP statement from my code. It is not necessary. So the code can run in silence how long your mouse is over the label.

                          If this is a really problem for you, let me know and I am sure that can be solved. But please tell me what trouble you have if the code is running when your mouse is over the label.

                          Comment

                          • Seth Schrock
                            Recognized Expert Specialist
                            • Dec 2010
                            • 2965

                            #14
                            The problem is that the screen flashes at about 5 flashes per second. Admittedly, there is only a little area on the screen where the mouse can be where it will do this. The code works fine in that the subform is selected. Your sample works perfectly without the flashing. I just don't know why mine works differently from yours. I did remove the beep portion of the code. I'm no longer at work, so I don't have access to the code until Monday.

                            Comment

                            • Mihail
                              Contributor
                              • Apr 2011
                              • 759

                              #15
                              I think my code also flash but is a little bit to screen refresh so it is not visible that flash.
                              Ok. I'll see until Monday how can be improved.

                              Have a nice week-end !

                              Comment

                              Working...