Curser Position in Textbox

Glue

Registered User.
Local time
Yesterday, 16:03
Joined
Jul 11, 2012
Messages
16
Is there a way to program how a textbox reacts to your cursor when the field is already populated (either by default value or by manual entry?)

This doesn't seem consistant in my DB. In some textboxes the cursor will highlight the text and then move on without deleting the data. In other areas when you tab into the textbox it will remove the data and you will only get a cursor replacing the data with a null value. At other times the cursor will be blinking at the front of the text and the user will need to go to his/her mouse to highlight the data in order to replace it.

To make things even more confusing, it does seem to matter if the field is a text field or a numeric field.

I've done some research and found this code, but it doesn't seem to work on a numeric field.

Private Sub GlassQty_Enter()
Me!GlassQty.SelStart = Me!GlassQty.SelLength
End Sub

Any help is greatly appreciated!!!
 
I'd probably use;
Code:
Me.FieldName.SelLength = Len(Me.FieldName)
In the field' On Enter event, and;
Code:
Me.Money.FieldName = 0
Me.Money.FieldName = Len(Me.FieldName)
In the On Click event.

The second piece of Code is required as click event happens after the enter event so if the user clicks into the field (rather than tabs in) the cursor will be positioned where the user clicked.
 
Now perhaps there are times when you do wish the user to be able to position his cursor anywhere in the text box. In this case you would need to declare a private variable in the Form's Module, lets call that variable IntCnt, so at the top of the Form's Code window just under Option Compare Database insert;
Code:
Dim IntCnt As Integer

In the Form's On Current event you would insert;
Code:
IntCnt = 0

Now in the On Click event of the field you would put;
Code:
If IntCnt = 0 Then
     Me.Money.FieldName = 0
     Me.Money.FieldName = Len(Me.FieldName)
End If

This code would mean that the first time a user clicked in the field the whole record would be selected, then on subsequent clicks the cursor would simply remain where the user placed it until they move to another record when IntCnt would be reset to zero.
 

Users who are viewing this thread

Back
Top Bottom