Avatar of shambalad
shambalad
Flag for United States of America

asked on 

SelLength update on textbox only works in debug

I have the following code set for when my text box 'txtDate' gets focus. The date is formatted as "mm/dd/yy".
When I run this subroutine in debug, breaking on the line after the one that references the 'Screen.ActiveControl', this routine works (i.e. the text in the text box is entirely selected). If I clear all breakpoints and then just click on the control, the cursor is positioned at the beginning of the text box and the text is not selected. Why is this happening?
There is a date value loaded in the field (e.g. "02/26/09") when the control gets focus.
Thanks,
Todd
Private Sub txtDate_GotFocus()
      Dim ctl As Control
      Set ctl = Screen.ActiveControl
      With ctl
      If IsDate(ctl) Then
            .SelStart = 0
            .SelLength = 8
         End If
      End With
   End Sub

Open in new window

Microsoft Access

Avatar of undefined
Last Comment
shambalad

8/22/2022 - Mon