Solved

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

Posted on 2016-11-04
17
56 Views
Last Modified: 2016-11-09
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
Comment
Question by:Dustin Stanley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
  • 2
17 Comments
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 41874802
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
 

Author Comment

by:Dustin Stanley
ID: 41874812
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
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 41874836
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 19

Expert Comment

by:Eric Sherman
ID: 41874853
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
 

Author Comment

by:Dustin Stanley
ID: 41874907
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
 
LVL 19

Assisted Solution

by:Eric Sherman
Eric Sherman earned 500 total points
ID: 41874910
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
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 41874912
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
 

Author Comment

by:Dustin Stanley
ID: 41874918
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
 

Accepted Solution

by:
Dustin Stanley earned 0 total points
ID: 41874928
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
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 41874933
Ok ... that works for you and gives you the action on the DoubleClick Event.

ET
0
 

Author Comment

by:Dustin Stanley
ID: 41874934
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
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 41874947
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
 
LVL 30

Expert Comment

by:hnasr
ID: 41875580
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
 

Author Comment

by:Dustin Stanley
ID: 41875642
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
 
LVL 30

Expert Comment

by:hnasr
ID: 41875670
I prefer the first one, since the second will affect any additional code required for dclick event.
0
 

Author Comment

by:Dustin Stanley
ID: 41875719
Gotcha! Thanks for the info!
0
 

Author Closing Comment

by:Dustin Stanley
ID: 41880276
Thank you for the help!
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question