Autotab after unbound text box is populated

  • Thread starter Thread starter Pete Provencher
  • Start date Start date
P

Pete Provencher

I have an unbound text box (CurrentAbstractor) that when it is populated
with a single character I want it to tab to the next field (SearchTMS). I
have the following settings:

CurrentAbstractor
AutoTab = Yes
Tab Stop = Yes
Tab Index = 0

SearchTMS
AutoTab = No
Tab Stop = Yes
Tab Index = 1


To set the length of CurrentAbstractor I use the following


Private Sub CurrentAbstractor_KeyPress(KeyAscii As Integer)

Call LimitKeyPress(Me.CurrentAbstractor, 1, KeyAscii)

End Sub
_________________________________________________

Private Sub CurrentAbstractor_Change()

Call LimitChange(Me.CurrentAbstractor, 1)

End Sub
_________________________________________________

Sub LimitKeyPress(ctl As Control, iMaxLen As Integer, KeyAscii As Integer)
On Error GoTo Err_LimitKeyPress
' Purpose: Limit the text in an unbound text box/combo.
' Usage: In the control's KeyPress event procedure:
' Call LimitKeyPress(Me.MyTextBox, 12, KeyAscii)
' Note: Requires LimitChange() in control's Change event also.

If Len(ctl.Text) - ctl.SelLength >= iMaxLen Then
If KeyAscii <> vbKeyBack Then
KeyAscii = 0
Beep
End If
End If

Exit_LimitKeyPress:
Exit Sub

Err_LimitKeyPress:

MsgBox "Error " & Err.Number & ": " & Err.Description
Resume Exit_LimitKeyPress
End Sub
____________________________________________________

Sub LimitChange(ctl As Control, iMaxLen As Integer)
On Error GoTo Err_LimitChange
' Purpose: Limit the text in an unbound text box/combo.
' Usage: In the control's Change event procedure:
' Call LimitChange(Me.MyTextBox, 12)
' Note: Requires LimitKeyPress() in control's KeyPress event also.

If Len(ctl.Text) > iMaxLen Then
MsgBox "Truncated to " & iMaxLen & " characters.", vbExclamation,
"Too long"
ctl.Text = Left(ctl.Text, iMaxLen)
ctl.SelStart = iMaxLen
End If

Exit_LimitChange:
Exit Sub

Err_LimitChange:

MsgBox "Error " & Err.Number & ": " & Err.Description
Resume Exit_LimitChange

End Sub
___________________________________________________________________


Any help will be appreciated.



Pete Provencher
 
Hi Pete,

That seems like overkill. The easiest way is to use a one-character
Input Mask such as L or A or &. Auto Tab should remain set to Yes.

Clifford Bass
 
When the user types in the single character I want it to automatically move
to the next field without having to hit enter or tab.

Pete Provencher
 
Private Sub CurrentAbstractor_KeyPress(KeyAscii As Integer)
Me.CurrentAbstractor = Chr$(KeyAscii)
Me.SearchTMS.SetFocus
End Sub

Damon
 
Hi Pete,

That is exactly what my suggestion does. Did you not try it?

Clifford Bass
 
Clifford's solution is the easiest, but do you care what character is
entered? If so, you need to test for it before proceeding....

Damon
 
Back
Top