Selecting Text

Eightball

New member
Local time
Today, 15:22
Joined
Nov 17, 2002
Messages
9
Does anyone know how to select the text in a textbox automatically so that if you start to type the old data disappears and is replaced with the new data. Thanks all.
 
Scott,
I put this at the end of the got focus event:

Me![text].SelStart=0
Me![text].SelLength = 1

It is a one character field. Is this supposed to work?

Thanks
 
Eightball,

Key question: When do you want the text in your textbox selected? When a form is first opened? If so, put code similar to this in the form's On Open Event.
Code:
If Len(Me.YourTextBoxName.Value) > 0 Then
    Me.YourTextBoxName.SetFocus
    Me.YourTextBoxName.SelLength = Len(Me.YourTextBoxName.Value)
End If
Or when you move to a new record? If so, put the same code in the form's On Current Event...

Etc.

Regards,
Tim
 
Hi Tim,
On the got focus event I use sendkeys to place a value in the field causing an on change event. I do a bunch of stuff not related to this field on the on change event. I would like the field selected after all this so the user can put a different value in if desired (more easily).
Thanks.
 
Sorry -- but I'm baffled because setting the value of a control by using a macro or Visual Basic doesn't trigger the change event for the control. You must type the data directly into the control, or set the control's Text property.

That's almost word-for-word from my A2K Help File...

Regards,
Tim
 
Hi Tim,
Well Sendkeys does..at least after the Sendkeys command the code in the on change event is running.
Eightball
 
Hello, Eightball,

Using VBA in A2K I can get SendKeys to fill a control at the On Click Event but not at the Got Focus Event, so I'm not able to replicate your situation. Yet, yes, when using SendKeys at the On Click Event my Change Event does fire -- so much for the Help file in that regard.

As an added point of interest, this VBA line:
Code:
SendKeys "Help"
will fire my change event four times, once for each letter.

And as for your specific problem, I can't get things to work with SendKeys but can do something when first using a line like this in the control's Click Event:
Code:
Me.YourTextBox.Value = "Help" 'put word "help" into textbox
And then lines like these in the control's AfterUpdate Event (to select the text).
Code:
If Not IsNull(Me.YourTextBox.Value) Then
    Me.YourTextBox.SelLength = Len(Me.YourTextBox.Value)
End If
Not a direct solution but perhaps a place to step off from...

Regards,
Tim
 

Users who are viewing this thread

Back
Top Bottom