selStart and selLength not returning values expected

RayG

New member
Local time
Today, 03:42
Joined
Jul 1, 2005
Messages
9
I need to determine the insertion point and whether any text is selcted in a bound text box. To do this I propose using selStart and selLength but in some circumstances they're not returning the values expected. As an aid to debugging I have this code in the control's OnExit Event:

Private Sub Name_Exit(Cancel As Integer)
Dim strMessage As String
strMessage = "Control: " & Screen.ActiveControl.Name & Chr(10)
strMessage = strMessage & "value: " & Screen.ActiveControl.Value & Chr(10)
strMessage = strMessage & "Start: " & Screen.ActiveControl.SelStart
strMessage = strMessage & " Length: " & Screen.ActiveControl.selLength
MsgBox (strMessage)
End Sub​

If the control contains 'abc' and you select the 'b', selStart correctly returns 1 and selLength1. But, if you type a 'x' say between the 'a' and the 'b' and the select the 'b', selStart returns 4 and selLength 0. Is this what's meant to happen and how do I get round it? I'm using Access 2002 SP2.
 

Users who are viewing this thread

Back
Top Bottom