Option Explicit

Const KEY_TAB = &H9
Const TAB_SIZE = 4

Sub cmdClear_Click ()
    txtFirstName.Text = ""
    txtLastName.Text = ""
    txtStreet.Text = ""
    txtCity.Text = ""
    txtState.Text = ""
    txtZipCode.Text = ""
    txtFirstName.SetFocus
End Sub

Sub cmdExit_Click ()
    End
End Sub

Sub Form_KeyPress (KeyAscii As Integer)
Dim Msg As String
Dim CrLf As String

    CrLf$ = Chr$(13) & Chr$(10)

    If KeyAscii = 13 Then
        Select Case ActiveControl.Tag
            Case "FirstName"
                txtLastName.SetFocus
            Case "LastName"
                txtStreet.SetFocus
            Case "Street"
                txtCity.SetFocus
            Case "City"
                txtState.SetFocus
            Case "State"
                txtZipCode.SetFocus
            Case "ZipCode"
                txtFirstName.SetFocus
        End Select
        KeyAscii = 0
    ElseIf ActiveControl.Tag = "State" Then
        If KeyAscii > Asc("a") And KeyAscii < Asc("z") Then
            KeyAscii = KeyAscii - 32
        End If
    ElseIf ActiveControl.Tag = "ZipCode" Then
        If InStr("0123456789-", Chr$(KeyAscii)) = 0 Then
            Msg$ = "Invalid Keystroke: " & Chr$(KeyAscii)
            Msg$ = Msg$ & CrLf$ & "Only 0 to 9 and - can be"
            Msg$ = Msg$ & CrLf$ & "can be used in Zip Codes!"
            MsgBox Msg$
            KeyAscii = 0
        End If
    End If
End Sub

