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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlight/Select field programmatically 1

Status
Not open for further replies.
Sep 21, 2005
17
0
0
US
How can one select or highlight the contents of an entire field to avoid doing so manually by passing the cursor over the entire field?

When tabbing through fields on a form, each field is fully highlighted or selected -- you can begin keying immediately. When using the cursor to position to a field, the edit bar of the cursor is positioned in front of the first character. I would like the entire field to be highlighted once I move the cursor to it.

Any ideas?

Regards,
Pete
 
Do you want to do this programmatically for particular fields or via options for all fields? If the latter,

Tools->Options, Keyboard tab, Behavior Entering Field option.
 
If you want the cursor to always go to the end of the text, look at Selstart

Private Sub Field1_GotFocus()
If IsNull(Field1) = False Then
Field1.SelStart = Len(Trim(Field1)) + 1
End If
End Sub

Regards
 
Further Clarification

I have optioned "Select entire Field" -- when I use the tab key it goes to each field and does what it is supposed to do -- it selects the entire field. However, when I use the mouse and position it to a particular field the the edit bar stands before the first character in the field. I would like to have the entire field selected upon entry to the control via the mouse.
 
Let us say you have a control called FileName:

Code:
Private Sub FileName_Click()
Me.FileName.SelStart = 0
Me.FileName.SelLength = Len(Trim(Me.FileName.Text))
End Sub

You will need code for each relevant field.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top