Link to home
Start Free TrialLog in
Avatar of Dustin Stanley
Dustin Stanley

asked on

Ms Access Form Control Text Box Select All Text Including Spaces and Dashes. Select ALL Characters In The Textbox.

I have been using this code to select all the text in a text box but if there is a space or dash it only selects up to the space or dash. How can I select it ALL?

Thanks!

Private Sub SkuMPN_DblClick(Cancel As Integer)
If Len(Me.SkuMPN & "") > 0 Then
    Me.SkuMPN.SelStart = 0
    Me.SkuMPN.SelLength = Len(Me.SkuMPN)
    Else
    End If
End Sub

Open in new window

Avatar of Eric Sherman
Eric Sherman
Flag of United States of America image

Try this ...

If Len(Me.SkuMPN & "") > 0 Then
    Me.SkuMPN.SetFocus
    Me.SkuMPN.SelStart = 0
    Me.SkuMPN.SelLength = Len(Me.SkuMPN)
    Else
    End If
End Sub


ET
Avatar of Dustin Stanley
Dustin Stanley

ASKER

Nope same thing. Lets say I have ABCD-1234  or ABCD 1234  It just highlights 1234. Unless it says ABCD1234 and then it highlights it all.
Try this ...

Move the code from the Double Click Event and just place it behind a temporary Command Button on your form and see what happens.

ET
I can duplicate what you are experiencing ... Seems like the DoubleClick Event is not the place to accomplish what you are trying to do.  Can you move it to another Event???


ET
Yeah it works in the OnClick Event but not DblClick. i would really like it to be in the dblClick event. If i click on it I just want the cursor to display to type but double click will highlight it. I wonder why????
SOLUTION
Avatar of Eric Sherman
Eric Sherman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Not sure why the Double Click Event does not run that code.  I checked in some of my apps and everywhere I've used the .SelStart and .SelLength it has always been in the OnClick Event.  This is the first time I've seen it used in the DoubleClick Event.

ET
Yeah I don't know. Maybe some higher expert might tune in and shine some light on the darkness. I appreciate the help and until I can figure it out I guess I will use the Onclick.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok ... that works for you and gives you the action on the DoubleClick Event.

ET
Correct and I didn't know this but I was trying to use it for copying all of the text easily. If you just right click the mouse it copies all the text in the box without code. It auto highlights everything.
Yep ... that was going to be my next question ... Let's see what you are trying to accomplish ... but sounds like it all worked out in the end.  Glad it is working.

ET
Add the line in BOLD.
Private Sub SkuMPN_DblClick(Cancel As Integer)
    IF Me.SkuMPN.SelLength <> Len(Me.SkuMPN) THEN Cancel = TRYE
If Len(Me.SkuMPN & "") > 0 Then
    Me.SkuMPN.SelStart = 0
    Me.SkuMPN.SelLength = Len(Me.SkuMPN)
    Else
    End If
End Sub
Thank you and yes that works also but I already requested a close on the question or I would have said this was an assisted answer.

Two ways that work are:
Private Sub SkuMPN_DblClick(Cancel As Integer)
If Len(Me.SkuMPN & "") > 0 Then
    Me.SkuMPN.SetFocus
    Me.SkuMPN.SelStart = 0
    Me.SkuMPN.SelLength = Len(Me.SkuMPN)
    Cancel = True
    Else
    End If
End Sub

Open in new window


OR

If Me.SkuMPN.SelLength <> Len(Me.SkuMPN) Then Cancel = True
If Len(Me.SkuMPN & "") > 0 Then
    Me.SkuMPN.SetFocus
    Me.SkuMPN.SelStart = 0
    Me.SkuMPN.SelLength = Len(Me.SkuMPN)
    Else
    End If

Open in new window

I prefer the first one, since the second will affect any additional code required for dclick event.
Gotcha! Thanks for the info!
Thank you for the help!