Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 83
  • Last Modified:

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

0
Dustin Stanley
Asked:
Dustin Stanley
  • 8
  • 7
  • 2
2 Solutions
 
Eric ShermanAccountant/DeveloperCommented:
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
0
 
Dustin StanleyEntrepreneurAuthor Commented:
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.
0
 
Eric ShermanAccountant/DeveloperCommented:
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
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
Eric ShermanAccountant/DeveloperCommented:
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
0
 
Dustin StanleyEntrepreneurAuthor Commented:
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????
0
 
Eric ShermanAccountant/DeveloperCommented:
Use the OnClick Event to run your code ...

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

ET
0
 
Eric ShermanAccountant/DeveloperCommented:
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
0
 
Dustin StanleyEntrepreneurAuthor Commented:
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.
0
 
Dustin StanleyEntrepreneurAuthor Commented:
I got it:

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



I found it at this thread :http://www.access-programmers.co.uk/forums/showthread.php?t=202616

Cancel = True

The guy says:

at the end of your code to stop the default double click action from kicking in once your code finishes.
0
 
Eric ShermanAccountant/DeveloperCommented:
Ok ... that works for you and gives you the action on the DoubleClick Event.

ET
0
 
Dustin StanleyEntrepreneurAuthor Commented:
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.
0
 
Eric ShermanAccountant/DeveloperCommented:
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
0
 
hnasrCommented:
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
0
 
Dustin StanleyEntrepreneurAuthor Commented:
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

0
 
hnasrCommented:
I prefer the first one, since the second will affect any additional code required for dclick event.
0
 
Dustin StanleyEntrepreneurAuthor Commented:
Gotcha! Thanks for the info!
0
 
Dustin StanleyEntrepreneurAuthor Commented:
Thank you for the help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 7
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now