Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie ? Stop autoselecting text 2

Status
Not open for further replies.

whitfield77

Technical User
Jan 9, 2002
108
US
I have designed a form with many fields on it. Whenever you enter a text field by tabbing to it, Access automatically selects all text in that field. Is there a way to stop this from happening? I just want the cursor to be positioned at the end of the text.

Thanks.
Chris
 
Add this code to the 'GotFocus' event of your code:

Private Sub MyField_GotFocus()
Me.MyField.SelStart = Len(Nz(Me.MyField, ""))
End Sub
 
Rather than entering the above code in a sub for each of the many text fields you say you have on this form, set this as the default behavior for the database.

1) Go to the "Tools" menu

2) Select "Options"

3) Select the "Keyboard" tab

4) Under "Behavior Entering Field" select "Go to End"

If you should have one or two fields where you DO want it selected on enter, you can code these fields separately and the default setting will be ignored.

Hope this helps.

The Missinglinq "It's got to be the going,
not the getting there that's good!"
-Harry Chapin
 
Missinglinq - Thanks for the suggestion. This will work very well for this particular form, as there are several text boxes.

beetee - Thanks also. I'll keep this in mind for the future.

Chris
 
Perhaps I spoke too soon. Is there a way to set the property that Missinglinq mentioned globally for the database, rather than going to each machine to change the behaviour?

Thanks again!

Chris
 
Try:

application.SetOption "Behavior Entering Field", 2


I should mention that really such preferences are up to your users. It may be better to create a preferences form and let them decide.
 
beetee,

Thanks for the info. I put this in the Form - Open event, wasn't sure where else to put it.

I agree, I'll have to look at a preferences form for the future. Right now there are only 6 of us that will be using this, but I have a feeling that my boss is going to want to push it out to a larger number of people. I've never had any training on Access (or any other development tool), but I create a simple form for us to use and suddenly I'm an Access programmer.

Anyway, thanks again for your help.

Chris
 
FormOpen isn't a bad place, but a better way may be to

1) Create an Autoexec macro (you can get help on it)
2) Create a function in a module to set the preferences
3) Use 'RunCode' in the macro to execute the function. (NOTE: it has to be a function, not a sub).

Tell your boss you want a raise.
 
The behavior on entering a given field can be significant depending on the usual functions associated with the field. A field where the data is usually changed each time the record is accessed (say, for example, fields to record a home care patient's latest vital signs) would best be served by having the current data selected on entry, so that the latest data can be entered with first selecting or deleting the current data. Fields whose data seldom changes (such as a patient's phone number) would best be served by not having the current data selected; it's way too easy to accidentally hit a key and have the current data disappear. Because of this, the application developer has the obligation to control this if possible.

Beetee's code is great (I've already got a use for it in mind). It would be even better if someone knows of a way to trap the current Access setting on a given machine so that it could be reset when your database is closed (resetting the On Enter behavior using this code resets the default for all Access databases on the given machine).

Anybody out there know how to do this?

The Missinglinq "It's got to be the going,
not the getting there that's good!"
-Harry Chapin
 
MsgBox Application.GetOption("Behavior Entering Field")

0 = Select Entire Field
1 = Go to Start of Field
2 = Go to End of Field

It's a very good idea what you're suggesting, but I'll leave the coding to you.

Have a great weekend all of you.
 
Thanks billpower!

The Missinglinq "It's got to be the going,
not the getting there that's good!"
-Harry Chapin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top