Share via

Remove focus from TextBox

Anonymous
2010-08-17T23:58:35+00:00

The code below calls UserForm OtherChoices and upon unloading OtherChoices

returns a value to TextBox100. Proble is that when done TextBox100 has the

Focus and the text is selected. Is there anything I can place after

OtherChoices.Show that will remove Focus from TextBox100?

Private Sub TextBox100_Enter()

Assignment1 = True

OtherChoices.Show

End Sub

Microsoft 365 and Office | Install, redeem, activate | For home | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Jay Freedman 207.7K Reputation points Volunteer Moderator
    2010-08-18T03:10:35+00:00

    Look at the properties of TextBox100 (and others) and verify that .HideSelection = True. Although this is the default, it might have been set to False at some time and forgotten.

    In case that isn't it...

    I tried creating a simpler version of this, and the SetFocus did exactly what we expected, moving the cursor to TextBox503 and not leaving anything highlighted in TextBox100.

    My RouteAssignment has three textboxes (TextBox1, TextBox 100, and TextBox503) and a command button. My OtherChoices has just a command button. The code in RouteAssignment is this:

    Private Sub btnOK_Click()

        Unload Me

    End Sub

    Private Sub TextBox100_Enter()

        OtherChoices.Show

        TextBox503.SetFocus

    End Sub

    and the code in OtherChoices is this:

    Private Sub btnOK_Click()

        RouteAssignment.TextBox100.Value = "foobar"

        Unload Me

    End Sub

    Running RouteAssignment, the cursor starts in TextBox1 and I tab to enter TextBox100. OtherChoices pops up, and I click its command button. The result is text in TextBox100 that is not selected or

    highlighted, and the cursor in TextBox 503.

    Maybe you can try a similar simplified setup to see whether it behaves the same for you; if so, add the other bits one at a time until you either find the culprit or complete a working copy.

    On Wed, 18 Aug 2010 01:16:54 +0000, Ordnance1 wrote:

    Thank you, Sorry I was not more clear. I had tried what you suggested but the text in TextBox100 remained selected. Let me share both sets of code involved:

     

    'This code is contained within the RouteAssignment UserForm

     

    Private Sub TextBox100_Enter()

    Assignment1 = True

    OtherChoices.Show

    TextBox503.SetFocus

    End Sub

     

    ----------------------------------------------------------------------------------------------------------------4---  

    'This code is contained within the OtherChoices UserForm

     

    Private Sub ListBox2_Click()

        If Assignment1 = True Then

            With Me.ListBox2

            If .ListIndex < 0 Then

                'nothing selected, same as cancel?            

            Else

                'Sets the Exempt from coverage status route

                RouteAssignment.TextBox100.Value = .List(.ListIndex, 0)

            Exempt1 = .List(.ListIndex, 13) 'Exempt from coverage status route 1

                

                If Exempt1 = "Yes" Then

                    RouteAssignment.OptionButton103.Value = True

                    RouteAssignment.OptionButton103.ForeColor = &HFF&

                    RouteAssignment.OptionButton104.Value = False

                End If

                If Exempt1 = "No" Then

                    RouteAssignment.OptionButton104.Value = True

                    RouteAssignment.OptionButton103.ForeColor = &H80000008

                    RouteAssignment.OptionButton103.Value = False

                End If

            End If

        End With

    End If

        Unload Me

    End Sub

     

     

     

    "Jay Freedman [MVP]" wrote in message news:*** Email address is removed for privacy ***...

    You never "remove focus" from anything. You just set the focus where you want it (which you didn't say). For example, if you want the focus to be in TextBox101, add the line

    TextBox101.SetFocus


    Jay Freedman

    MS Word MVP  FAQ: http://word.mvps.org

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Jay Freedman 207.7K Reputation points Volunteer Moderator
    2010-08-18T00:33:55+00:00

    You never "remove focus" from anything. You just set the focus where you want it (which you didn't say). For example, if you want the focus to be in TextBox101, add the line

    TextBox101.SetFocus


    Jay Freedman

    MS Word MVP  FAQ: http://word.mvps.org

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2010-08-18T03:21:04+00:00

    Thanks I will work on that tonight

    "Jay Freedman [MVP]" wrote in message news:*** Email address is removed for privacy ***...

    Look at the properties of TextBox100 (and others) and verify that .HideSelection = True. Although this is the default, it might have been set to False at some time and forgotten.

    In case that isn't it...

    I tried creating a simpler version of this, and the SetFocus did exactly what we expected, moving the cursor to TextBox503 and not leaving anything highlighted in TextBox100.

    My RouteAssignment has three textboxes (TextBox1, TextBox 100, and TextBox503) and a command button. My OtherChoices has just a command button. The code in RouteAssignment is this:

    Private Sub btnOK_Click()

        Unload Me

    End Sub

    Private Sub TextBox100_Enter()

        OtherChoices.Show

        TextBox503.SetFocus

    End Sub

    and the code in OtherChoices is this:

    Private Sub btnOK_Click()

        RouteAssignment.TextBox100.Value = "foobar"

        Unload Me

    End Sub

    Running RouteAssignment, the cursor starts in TextBox1 and I tab to enter TextBox100. OtherChoices pops up, and I click its command button. The result is text in TextBox100 that is not selected or

    highlighted, and the cursor in TextBox 503.

    Maybe you can try a similar simplified setup to see whether it behaves the same for you; if so, add the other bits one at a time until you either find the culprit or complete a working copy.

    On Wed, 18 Aug 2010 01:16:54 +0000, Ordnance1 wrote:

    Thank you, Sorry I was not more clear. I had tried what you suggested but the text in TextBox100 remained selected. Let me share both sets of code involved:

     

    'This code is contained within the RouteAssignment UserForm

     

    Private Sub TextBox100_Enter()

    Assignment1 = True

    OtherChoices.Show

    TextBox503.SetFocus

    End Sub

     

    ----------------------------------------------------------------------------------------------------------------4---  

    'This code is contained within the OtherChoices UserForm

     

    Private Sub ListBox2_Click()

        If Assignment1 = True Then

            With Me.ListBox2

            If .ListIndex < 0 Then

                'nothing selected, same as cancel?            

            Else

                'Sets the Exempt from coverage status route

                RouteAssignment.TextBox100.Value = .List(.ListIndex, 0)

            Exempt1 = .List(.ListIndex, 13) 'Exempt from coverage status route 1

                

                If Exempt1 = "Yes" Then

                    RouteAssignment.OptionButton103.Value = True

                    RouteAssignment.OptionButton103.ForeColor = &HFF&

                    RouteAssignment.OptionButton104.Value = False

                End If

                If Exempt1 = "No" Then

                    RouteAssignment.OptionButton104.Value = True

                    RouteAssignment.OptionButton103.ForeColor = &H80000008

                    RouteAssignment.OptionButton103.Value = False

                End If

            End If

        End With

    End If

        Unload Me

    End Sub

     

     

     

    "Jay Freedman [MVP]" wrote in message news:*** Email address is removed for privacy ***...

    You never "remove focus" from anything. You just set the focus where you want it (which you didn't say). For example, if you want the focus to be in TextBox101, add the line

    TextBox101.SetFocus


    Jay Freedman

    MS Word MVP  FAQ: http://word.mvps.org

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2010-08-18T01:16:54+00:00

    Thank you, Sorry I was not more clear. I had tried what you suggested but the text in TextBox100 remained selected. Let me share both sets of code involved:

    'This code is contained within the RouteAssignment UserForm

    Private Sub TextBox100_Enter()

    Assignment1 = True

    OtherChoices.Show

    TextBox503.SetFocus

    End Sub

    ----------------------------------------------------------------------------------------------------------------4---

    'This code is contained within the OtherChoices UserForm

    Private Sub ListBox2_Click()

    If Assignment1 = True Then

    With Me.ListBox2

    If .ListIndex < 0 Then

                'nothing selected, same as cancel?            

            Else

                'Sets the Exempt from coverage status route

                RouteAssignment.TextBox100.Value = .List(.ListIndex, 0)

    Exempt1 = .List(.ListIndex, 13) 'Exempt from coverage status route 1

    If Exempt1 = "Yes" Then

                    RouteAssignment.OptionButton103.Value = True

                    RouteAssignment.OptionButton103.ForeColor = &HFF&

                    RouteAssignment.OptionButton104.Value = False

                End If

                If Exempt1 = "No" Then

                    RouteAssignment.OptionButton104.Value = True

                    RouteAssignment.OptionButton103.ForeColor = &H80000008

                    RouteAssignment.OptionButton103.Value = False

                End If

    End If

        End With

    End If

    Unload Me

    End Sub

    "Jay Freedman [MVP]" wrote in message news:*** Email address is removed for privacy ***...

    You never "remove focus" from anything. You just set the focus where you want it (which you didn't say). For example, if you want the focus to be in TextBox101, add the line

    TextBox101.SetFocus

     


    Jay Freedman

    MS Word MVP  FAQ: http://word.mvps.org

    Was this answer helpful?

    0 comments No comments