Consulting

Results 1 to 3 of 3

Thread: Keep code running in mouse up event

  1. #1
    VBAX Regular
    Joined
    Jan 2020
    Posts
    6
    Location

    Keep code running in mouse up event

    I have some text boxes with code that I need to keep running as long as I am in that text box. The user would click on a text box and select their object (in the application). After selecting the object, the user shouldn't have to click on the text box again to select a different object if they so choose to. Also, the user should have the freedom to select a different text box (which would have the same type of code, with minor variances). My first attempt was something as shown below in pseudo code.

    textboxA_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    
       Do While selected object count < 2
          DoEvents
           *Process Selection*
          If valid selection then
             display information about selection on form
          End If
          Exit Do
       Loop
    
       TextBoxA_MouseUp 1, 0, X, Y
    
    End Sub
    This type of code would be used for textboxB with some differences in the Process Selection bit. Setting focus to the text box won't work since it does not trigger the Do While loop. I would need some way to run the Do While loop again, even after a valid selection. Maybe I need to nest the Exit Do in an If Then that checks to see if any of the other text boxes have the ActiveControl.TabIndex. If the condition is true, then I exit the current mouse event sub. The question I have with this is that once I click on another text box, will I get moved to that text box before I'm able to make a decision based on the ActiveControl.TabIndex value?

  2. #2
    Moderator VBAX Wizard SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,083
    Location
    Dim tbxA_MouseUp_IsRunning as Boolean
    Dim tbxB_MouseUp_IsRunning as Boolean
    Private Sub textboxA_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    
    tbxB_MouseUp_IsRunning = False
    tbxA_MouseUp_IsRunning = True
    
    Do While tbxA_MouseUp_IsRunning
           Do While selected object count < 2
                 DoEvents
           *Process Selection*
                 If valid selection then
                         display information about selection on form
                 End If
                Exit Do
           Loop
    Loop
       TextBoxA_MouseUp 1, 0, X, Y
    
    End Sub
    Private Sub textboxB_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    
    tbxA_MouseUp_IsRunning = False
    tbxB_MouseUp_IsRunning = True
    
    
    Do While tbxB_MouseUp_IsRunning
           Do While selected object count < 2
                 DoEvents
           *Process Selection*
                    If valid selection then
                          display information about selection on form
                    End If
                    Exit Do
         Loop
    Loop
       TextBoxB_MouseUp 1, 0, X, Y
    
    End Sub
    I always expect the student to do their homework and find all the errrors I leeve in.

    Please take the time to read the Forum FAQ

  3. #3
    VBAX Regular
    Joined
    Jan 2020
    Posts
    6
    Location
    Thank you, this worked.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •