DCrake
Remembered
- Local time
- Today, 20:29
- Joined
- Jun 8, 2005
- Messages
- 8,626
Cany anyone shed light on why this code does not work?
This code is fired on the on click of a button. The issue is that the SelStart always returns zero not the actual position in the string where the curson is.
It works fine in VB but fails in Access.
It seems that when a textbox looses focus by way of clicking on a button when the code passes back the focus to the textbox the cursor is always at the start of the text. This may have something to do with the behaviour entering field setting, don't know.
Code:
Private Sub GetChar(CtrlName As String)
Dim Ctrl As Control
Set Ctrl = Me(CtrlName)
txtUpChar.SetFocus
If txtUpChar.SelStart = 0 Or txtUpChar.SelStart = Len(txtUpChar.Text) Then
txtUpChar.Text = txtUpChar.Text & Ctrl.Caption
ElseIf txtUpChar.SelLength = 0 Then
txtUpChar.Text = Mid(txtUpChar.Text, 1, txtUpChar.SelStart) & _
Ctrl.Caption & Mid(txtUpChar.Text, txtUpChar.SelStart + 1)
Else
txtUpChar.Text = Mid(txtUpChar.Text, 1, txtUpChar.SelStart) & _
Ctrl.Caption & _
Mid(txtUpChar.Text, txtUpChar.SelStart + txtUpChar.SelLength + 1)
End If
txtUpChar.SelStart = Len(txtUpChar.Text)
End Sub
This code is fired on the on click of a button. The issue is that the SelStart always returns zero not the actual position in the string where the curson is.
It works fine in VB but fails in Access.
It seems that when a textbox looses focus by way of clicking on a button when the code passes back the focus to the textbox the cursor is always at the start of the text. This may have something to do with the behaviour entering field setting, don't know.