Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 03-18-2009, 04:19 PM   #1
k3v1np
Registered User
 
Join Date: Mar 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
k3v1np is on a distinguished road
Highlighting the contents of a textbox on entry.

Looking for a VBA solution. I'm trying to have the contents of a textbox highlighted on entering it with the cursor so that it can be overwritten with the first keystroke. I have scoured a bunch of forums and googled the s_ _ t out of "highlight contents textbox" with zero success.

k3v1np is offline   Reply With Quote
Old 03-18-2009, 04:31 PM   #2
missinglinq
AWF VIP
 
missinglinq's Avatar
 
Join Date: Jun 2003
Location: Richmond (Virginia that is!)
Posts: 6,320
Thanks: 11
Thanked 721 Times in 671 Posts
missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light
Re: Highlighting the contents of a textbox on entry.

If you want it to happen to all fields,

Goto Tools - Options - Keyboard and set "Behavior on Entering Field" to "Select Entire Field."

To just do it for a given field:
Code:
Private Sub FieldName_GotFocus()
  FieldName.SelStart = 0
  FieldName.SelLength = Len(Me.FieldName)
End Sub
__________________
The Devil's in the Details!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


(All code solutions tested in Access 2003/2007, before posting, unless otherwise noted.)
missinglinq is offline   Reply With Quote
Old 03-19-2009, 07:10 AM   #3
k3v1np
Registered User
 
Join Date: Mar 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
k3v1np is on a distinguished road
Re: Highlighting the contents of a textbox on entry.

Thanks for your help.
(see attached file)
However, I must be doing something wrong cause I can't get it to work. I put the appropriate code in the on got focus event of the fname text box. When I click in that box it does not highlight the text. Also this is Access 2007 so i can't find the menu option to change the setting that you describe.
Attached Files
File Type: zip database.zip (26.6 KB, 448 views)

k3v1np is offline   Reply With Quote
Old 03-22-2009, 03:57 PM   #4
k3v1np
Registered User
 
Join Date: Mar 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
k3v1np is on a distinguished road
Re: Highlighting the contents of a textbox on entry.

I found the same examples that missinglinq posted above on a few other forums and I can't understand why I am unable to get it to work like i think it should. Should it not highlight all the text in the field when you click in it with the mouse coursor? Cause mine just won't do that. Something so simple shouldn't be so difficult. Or is it me who is simple?
k3v1np is offline   Reply With Quote
Old 03-22-2009, 06:04 PM   #5
evanscamman
Newly Registered User
 
Join Date: Feb 2007
Posts: 274
Thanks: 0
Thanked 1 Time in 1 Post
evanscamman is on a distinguished road
Re: Highlighting the contents of a textbox on entry.

The code is good code. If you try to enter the control by tabbing into it you will see that it does select the text.

The problem with clicking into the control is that the click event overwrites your selection.

This may not be the cleanest work-a-round, but you could use the timer event to get around this:

Private Sub FieldName_GotFocus()
Me.TimerInterval = 10
End Sub

Private Sub Form_Timer
FieldName.SelStart = 0
FieldName.SelLength = Len(Me.FieldName)
End Sub


This delays the Select code by 10 milliseconds and gives the mouse event time to have already fired.

Evan
evanscamman is offline   Reply With Quote
Old 03-22-2009, 06:15 PM   #6
missinglinq
AWF VIP
 
missinglinq's Avatar
 
Join Date: Jun 2003
Location: Richmond (Virginia that is!)
Posts: 6,320
Thanks: 11
Thanked 721 Times in 671 Posts
missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light
Re: Highlighting the contents of a textbox on entry.

I haven't had anyone have trouble with this for ages, but I seem to remember from way back in my addled mind that occasionally you also need to place the code in the textbox OnClick event. Note that that's in addition to the GotFocus event.

Don't run 2007, so I can't tell where you have to for Options.

Just out of curiosity, do you have any VBA code that runs? In version 2007, no VBA code will execute unless that the folder holding the database has been designated as a “trusted” location.

To trust your folder, click:
* Office Button (top left)
* Access Options (bottom of dialog)
* Trust Center (left)
* Trust Center Settings (button)
* Trusted Locations (left)
* Add new location (button)
__________________
The Devil's in the Details!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


(All code solutions tested in Access 2003/2007, before posting, unless otherwise noted.)
missinglinq is offline   Reply With Quote
Old 03-22-2009, 10:06 PM   #7
k3v1np
Registered User
 
Join Date: Mar 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
k3v1np is on a distinguished road
Re: Highlighting the contents of a textbox on entry.

aaaah YES. Placing it the same code in the on click property solves the problem. Thank you, thank you and thank you.

k3v1np is offline   Reply With Quote
Old 01-26-2015, 03:04 PM   #8
ndfan77
Newly Registered User
 
Join Date: Jan 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
ndfan77 is on a distinguished road
Re: Highlighting the contents of a textbox on entry.

I realize it is now six years later but, I ran into a need for this too -- and wanted to add that if you want users to retain the ability to also select existing text with the mouse, the TextBox Click event needs to be a little smarter:

Code:
Private Sub MyTextBox_Click()
    If MyTextBox.SelLength = 0 Then     'Don't change selection if user has already selected text
        MyTextBox.SelStart = 0
	MyTextBox.SelLength = Len(MyTextBox.Value & "")
    End If
End Sub
ndfan77 is offline   Reply With Quote
Old 01-16-2017, 10:42 PM   #9
atrium
Newly Registered User
Silver Supporter
 
Join Date: May 2014
Location: Gold Coast, Australia
Posts: 200
Thanks: 12
Thanked 10 Times in 10 Posts
atrium is on a distinguished road
Thumbs up Re: Highlighting the contents of a textbox on entry.

Missinglinq

The last bit of code to highlight the text worked wonders.

Thank you

Atrium
atrium is offline   Reply With Quote
Old 01-17-2017, 05:54 AM   #10
missinglinq
AWF VIP
 
missinglinq's Avatar
 
Join Date: Jun 2003
Location: Richmond (Virginia that is!)
Posts: 6,320
Thanks: 11
Thanked 721 Times in 671 Posts
missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light
Re: Highlighting the contents of a textbox on entry.

Glad we could help once more!

Linq ;0)>
__________________
The Devil's in the Details!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


(All code solutions tested in Access 2003/2007, before posting, unless otherwise noted.)
missinglinq is offline   Reply With Quote
Old 10-14-2019, 02:48 PM   #11
Gavx
Newly Registered User
 
Join Date: Mar 2014
Posts: 136
Thanks: 35
Thanked 0 Times in 0 Posts
Gavx is on a distinguished road
Re: Highlighting the contents of a textbox on entry.

I tried to implement this on a text box that is formatted for Currency but the code only selects the numbers to the left of the decimal point.
Can anyone please advise the fix?

thanks
gavin
Gavx is offline   Reply With Quote
Old 10-14-2019, 05:32 PM   #12
missinglinq
AWF VIP
 
missinglinq's Avatar
 
Join Date: Jun 2003
Location: Richmond (Virginia that is!)
Posts: 6,320
Thanks: 11
Thanked 721 Times in 671 Posts
missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light
Re: Highlighting the contents of a textbox on entry.

Quote:
Originally Posted by Gavx View Post
I tried to implement this on a text box that is formatted for Currency but the code only selects the numbers to the left of the decimal point.
Can anyone please advise the fix?

Never run into this before but you are indeed correct! Only workaround I could come up with (it's been a very long day and I going to La La Land soon) is to assign the field as Text then use this

Code:
txtCurrency.SelStart = 0
txtCurrency.SelLength = Left(txtCurrency, InStr(txtCurrency, ".")) & Mid(InStr(TxtCurrency, ","), 3)

You'd have to deal with using one of the Conversion Functions when dealing with the Field if you're going to be doing math with it...same thing, in reverse, if you're using math to derive the amount.

Hope this helps!

Linq ;0)>
__________________
The Devil's in the Details!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


(All code solutions tested in Access 2003/2007, before posting, unless otherwise noted.)
missinglinq is offline   Reply With Quote
Old 10-14-2019, 10:52 PM   #13
Pat Hartman
Super Moderator
 
Join Date: Feb 2002
Location: Stratford,Ct USA
Posts: 28,316
Thanks: 15
Thanked 1,601 Times in 1,520 Posts
Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all
Re: Highlighting the contents of a textbox on entry.

In my databases, this is the default behavior. Check the properties of the database. Perhaps yours are different.
Attached Images
File Type: jpg SelectEntireField.JPG (59.5 KB, 195 views)
__________________
Bridge Players Still Know All the Tricks
Pat Hartman is offline   Reply With Quote
Old 10-14-2019, 11:03 PM   #14
isladogs
High Noon Moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 11,360
Thanks: 115
Thanked 3,110 Times in 2,828 Posts
isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold isladogs is a splendid one to behold
Re: Highlighting the contents of a textbox on entry.

If your app is to be run by several users/ on several workstations, do bear in mind that the settings in Pat's screenshot apply to the client rather than the current database.
In other words you can't rely on that setting being true for other users
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Colin (Mendip Data Systems)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Common sense and a sense of humour are the same thing, moving at different speeds. (Clive James - RIP)
isladogs is offline   Reply With Quote
Old 10-15-2019, 05:04 PM   #15
Pat Hartman
Super Moderator
 
Join Date: Feb 2002
Location: Stratford,Ct USA
Posts: 28,316
Thanks: 15
Thanked 1,601 Times in 1,520 Posts
Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all Pat Hartman is a name known to all
Re: Highlighting the contents of a textbox on entry.

I'm working on getting that changed. Every year when I send my Christmas wish list to the MS Access team, a way to control properties for THIS database specifically and for new databases created by me in general is near the top of the list.

Keep in mind that what I posted is the default setting. If the app is distributed to people who do not themselves create Access databases, the settings would not have been changed. However, if the app will be used by users who do get their hands dirty with Access, then Colin is correct.

__________________
Bridge Players Still Know All the Tricks
Pat Hartman is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
on entering a number in a textbox, check if entry already exists? kate10123 Forms 7 12-29-2009 11:12 AM
TextBox not allowing data entry RcNorth Forms 2 01-20-2009 07:48 AM
unbound textbox errors when depending textbox encounters delay smile Modules & VBA 3 11-16-2008 07:18 AM
Trouble Highlighting Contents in text box MikeAngelastro Forms 3 04-18-2003 05:17 PM
Table of Contents Hayley Baxter Reports 1 12-18-2002 08:28 AM




All times are GMT -8. The time now is 05:03 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World