5 VisualBasicSource: Max lenght & Auto Tab

Q: Max lenght & Auto Tab
First, thanks for providing this valuable service. I've almost given up trying to get an answer from Micosoft VB support. I really felt the impact when your web site was not available the past week. I need to limit the size of some text boxes. Not only that, I need to "auto-tab" to the next field when a user enters the maximum number of characters. I've tried putting logic in the Keypress event for the fields but I'm getting some crazy numbers. On some fields, I have to test for a LEN > 1 character less than I want to limit the field to. For example if I want to limit a field to 9 characters, I put the following logic into the KeyPress event: Private Sub txtClaimNo_KeyPress(KeyAscii As Integer) If (Len(txtClaimNo.Text) > 8 And (KeyAscii <> 8)) Or (KeyAscii = 13) Then txtPatientID.SetFocus End If End Sub I wanted the user to be able to use the backspace key without tabbing to the next field (that's the test for Keyascii=8). On other fields, like a 2-digit month or day value for a calendar date, I have to test for a LEN > 0. It looks like this: Private Sub txtRecvDtMM_KeyPress(KeyAscii As Integer) If (Len(txtRecvDtMM.Text) > 0 And (KeyAscii <> 8)) Or (KeyAscii = 13) Then txtRecvDtDD.SetFocus End If End Sub I can understand why the LEN value is 1 less (starts off as zero) but can you explain why some fields only work when I test for 2 less? Is there a better way to auto-tab when a user enters the maximum number of characters? I would be pleased to have you visit my web site at http://www.iwaynet.net/~fyoung Frederick Young; fyoung@iwaynet.net

A: Just check the example LimitText