This Is And Easy One -- Auto-Highlight Text in Cell (1 Viewer)

asulliva

Registered User.
Local time
Today, 04:02
Joined
Jul 15, 2008
Messages
19
How do I set a cell to auto-highlight the text inside of it when it gains focus?

I don't want to have to highlight the text manually to delete/alter it each time as this is a fairly big form.
 

dkinley

Access Hack by Choice
Local time
Today, 06:02
Joined
Jul 29, 2008
Messages
2,016
I am not sure in earlier versions but in Access '07 you can alter this in Access Options.

Under the Advanced tab, select "Select Entire Field" under "Behavior Entering Field".

-dK
 

missinglinq

AWF VIP
Local time
Today, 07:02
Joined
Jun 20, 2003
Messages
6,423
To do it for all textboxes in a database:

Goto Tools - Options - Keyboard
Set Behavior Entering Field to Select Entire Field

For an individual field:
Code:
Private Sub ControlName_Click()
 Me.ControlName.SelStart = 0
 Me.ControlName.SelLength = Len(Me.ControlName)
End Sub

Private Sub ControlName_GotFocus()
 Me.ControlName.SelLength = Len(Me.ControlName)
End Sub
 

asulliva

Registered User.
Local time
Today, 04:02
Joined
Jul 15, 2008
Messages
19
To do it for all textboxes in a database:

Goto Tools - Options - Keyboard
Set Behavior Entering Field to Select Entire Field

For an individual field:
Code:
Private Sub ControlName_Click()
 Me.ControlName.SelStart = 0
 Me.ControlName.SelLength = Len(Me.ControlName)
End Sub
 
Private Sub ControlName_GotFocus()
 Me.ControlName.SelLength = Len(Me.ControlName)
End Sub

Will this code work if the cell is tabbed to rather than clicked on?

Also...my Tools/Options is grayed out. The guy who designed this DB/Form is no longer with the company and I wasn't around when he created it. I'm sort of an Access newb.
 

missinglinq

AWF VIP
Local time
Today, 07:02
Joined
Jun 20, 2003
Messages
6,423
Will this code work if the cell is tabbed to rather than clicked on?
Yes.

Also...my Tools/Options is grayed out.

Options will be grayed out when Access is first opened; is it grayed out after you've actually loaded your database? If so you may very well be out of luck. You need to look at the database file thru Windows Explorer and see whether the extension is MDB or MDE. If it's MDE you need to use Windows Search and look for a file with the same name but an MDB extension. MDE fields are "locked" to design changes, which is what you're trying to do. You can't change the code on an MDE file either, so if this is the case, you'll have to find the original MDB file to make changes.
 

asulliva

Registered User.
Local time
Today, 04:02
Joined
Jul 15, 2008
Messages
19
The file I am opening is a .MDB

I'll walk you through the process I take to open the form to where I'm editing it and maybe you can find a step where I would be able to somehow access these options...

-double click .MDB file
-MS Access Pop-Up: "Security Warning: Unsafe expressions are not blocked.
Do you want to block unsafe expressions?"
-I choose to not block unsafe expressions
-Another warning saying the code in the file may be intended to harm my computer, open anyway? I choose "yes" (keep in mind I'm on a heavily secure work computer)
-A Custom Login Screen appears with my company logo, etc on it.
-I log in using the appropriate credentials
-I choose which Menu I want to open (there's finance, budget, etc)
-the main form plus sub forms open
-i click the "database window" icon in my top toolbar, highlight the form I want, and click the "design view" icon

I guess I don't mind plugging the code into every cell I need formatted in this manner. Do I put it in each cell's "On Enter" event?
 

missinglinq

AWF VIP
Local time
Today, 07:02
Joined
Jun 20, 2003
Messages
6,423
Just do it like I posted, one in the textbox OnClick and one in the GotFocus event. I have no idea why code in the GotFocus doesn't do the job by itself, but it doesn't. Have to have it in both places.

I'm guessing from your description that your company's IT department has placed restrictions on your PC so that you can't access Options; some larger companies do that. It gives their IT department a reason to exist.

One word of warning; you want to be very careful about using this! Having every field hi-lighted each time the field is entered can be a recipe for disaster. If any key is touched the data is gone! This can be really bad in dome situations. I've known users to accidentally delete data and, in order to cover up their mistake, enter whatever comes into their head first. I'll use this on a field that is updated most times when the record is accessed, but not on a field that seldom if ever change. You wouldn't want to wipe out someone's ID number or phone number orsuch.
 

asulliva

Registered User.
Local time
Today, 04:02
Joined
Jul 15, 2008
Messages
19
Alright I'll give that code a shot.

Thank you very much for all of your help.

Also, thanks for the warning but it should fine since the only cells that are "enabled" on the form are ones that are updated very regularly.
 

asulliva

Registered User.
Local time
Today, 04:02
Joined
Jul 15, 2008
Messages
19
I should have mentioned that the default value in the text box is a decimal (0.00) and all values that will ever be in the box will more than likely be decimals. Currently everything looks to be working except it highlights only the numbers left of the decimal. I'd like it all highlighted if possible...
 

Users who are viewing this thread

Top Bottom