highlighting the text in a textbox

M

MS

Hi,

Probably a silly question but I can't fathom out how to do it...

Simple ADP form tied to a view. Some fields are fixed width chars. This
appears to mean that when a user enters a cell, it is in effect X spaces
(where X is the length of the char field). I.e. " ".

This means that the user must delete the spaces first before they can enter
there text.

Is there any way, when the textbox gains the focus to highlight the spaces
so that the whatever the user types simply overwrites them? I can't find any
textbox methods or properties that seem to be able to let me do this...

An analogy would be the behaviour of the address bar in a browser....

Any advice or pointers are gratefully received.

Kind thanks

Chris.
 
W

Wayne Morgan

Check out Tools|Options|Keyboard tab, then the Behavior Entering Field
option. This will affect all textboxes. For individual textboxes you would
need to use the SelStart and SelLength commands in the GotFocus or Enter
event of the textbox.

Example (untested):
If Len(Me.ActiveControl.Text) > 0 And Len(Replace(Me.ActiveControl.Text, "
", "")) = 0 Then
Me.ActiveControl.SelStart = 0
Me.ActiveControl.SelLength = Len(Me.ActiveControl)
End If

The first part if the If checks to see if something is there, the second
part replaces blank spaces with zero length strings. If the only thing there
was blank spaces, the length should now be zero.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top