Trying and Failing to Select (Highlight) Existing Text In Userform Textbox

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,562
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am using this code to try to highlight (select) the existing value in a textbox to allow a user to overtype a new value over the existing without having to manually select. Unfortunately it's not working. The value is not highlighted and the uer has to manually highlight it or delete it. Open to suggestions to improve.

Code:
Private Sub tb_s1_lwr_Enter()
    If trnfrm_new = False Then
        With Me.tb_s1_lwr
            Oval = .Value
            .BackColor = RGB(166, 166, 166) 'RGB(206, 234, 232)
            .SelStart = 0
            .SelLength = Len(Me.tb_s1_lwr)
        End With
        Exit Sub 'prevents field clearing
    End If
    tb_lower_enter Me, 1 '{frm_trn_services}*
End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
I have updated to this code:
Rich (BB code):
Private Sub tb_s1_lwr_Enter()
    'checked: 21-03-04
    'Stop
    If trnfrm_new = False Then
        With Me.tb_s1_lwr
            Oval = .Value
            .BackColor = RGB(166, 166, 166) 'RGB(206, 234, 232)
            .SelStart = 0
            .SelLength = Len(.Text)
        End With
        ForceFocus Me.tb_s1_lwr
        Exit Sub 'prevents field clearing
    End If
    tb_lower_enter Me, 1 '{frm_trn_services}*
End Sub

With the "ForceFocus" procedure being:
Code:
Private Sub ForceFocus(ByVal Ctrl As Control)
    Set OCtrl = Ctrl
    Application.OnTime Now, "DelayedSetFocus"
End Sub

I've used this method with other textboxes, but in this case, I'm getting a "Sub or Function not defined" error with the line highlighted in red.
 
Upvote 0

Forum statistics

Threads
1,214,400
Messages
6,119,288
Members
448,885
Latest member
LokiSonic

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top