Avatar of Fordraiders
Fordraiders
Flag for United States of America asked on

textbox parameters for data entry

I have a text box on a form that needs the following requirements:

1. always UPPER CASE.
2. MUST be 5 characters(alphanumeric) in length.
    A. Can NOT end in "AA"

SSDAA  <<   will not work
DS333  <  -- GOOD
FGH56 <--- GOOD
GAAAA < --- WILL NOT WORK

Thanks
fordraiders
Microsoft Access

Avatar of undefined
Last Comment
Fordraiders

8/22/2022 - Mon
Fordraiders

ASKER
ok for setting UPPERCASE
Public Sub ConvertToCaps(KeyAscii As Integer)
' Converts text typed into control to upper case

   Dim strCharacter As String
   
   ' Convert ANSI value to character string.
   strCharacter = Chr(KeyAscii)
   ' Convert character to upper case, then to ANSI value.
   KeyAscii = Asc(UCase(strCharacter))

End Sub

Open in new window


For setting character length:
Sub LimitFieldSize(KeyAscii, MAXLENGTH)
      Dim C As Control
      Dim CLen As Integer

      Set C = Screen.ActiveControl

      ' Exit if a non-printable character is typed.
      If KeyAscii < 32 Then Exit Sub

      ' Exit if typing replaces a selection.
      If C.SelLength > 0 Then Exit Sub

      ' Fetch length of current contents + 1 for the character typed.
      CLen = Len(C.Text & "") + 1

      ' Are there trailing spaces to contend with?
      If C.SelStart + 1 > CLen Then CLen = C.SelStart + 1

      ' Is length of string greater than max?
      If CLen > MAXLENGTH Then
        Beep
        KeyAscii = 0
      End If

   End Sub

Open in new window



Calling the events:
Private Sub txtSubTrack_KeyPress(KeyAscii As Integer)
On Error Resume Next
LimitFieldSize KeyAscii, 5
ConvertToCaps KeyAscii
End Sub

Private Sub txtSubTrackName_KeyPress(KeyAscii As Integer)
'On Error Resume Next
'LimitFieldSize KeyAscii, 5
ConvertToCaps KeyAscii

End Sub

Open in new window


For now just need:
An alarm to tell me if the last 2 characters  are  "AA"  ?
ASKER CERTIFIED SOLUTION
Rey Obrero (Capricorn1)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Dale Fye

Presonally, I prefer to use the controls AfterUpdate event, or the Form_BeforeUpdate event to check for field validity.  By putting it in the Form_BeforeUpdate event, you allow the user to tab out of the control even if they have not finished entering the information (maybe they forgot a value and need to look it up).

Just my 2 cents.

Dale
Fordraiders

ASKER
Thanks very much !
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes