Results 1 to 3 of 3
  1. #1
    sra2786 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Location
    Cincinnati, OH
    Posts
    38

    Data Validation using LIKE operator

    I want to validate user input in the BeforeUpdate so that I can create a custom message if the data is in the wrong format. I tried the following but it does not check for uppercase letters.


    An example of a correct format is CATX12345. Can someone tell me how to check for uppercase letters?

    blnIsValid = (strIn Like "[A-Z][A-Z][A-Z][A-Z]#####")

    Thanks.
    Sandy

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    You can ignore what the user inputs and force the entry to uppercase with the UCASE function:
    strin=ucase(strin)

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Here is a function I use to check a password "complexity", you can see how I check for UCase, you can easily adapt it for your needs:
    Code:
    Public Function IsComplex(sInput As String) As Boolean
    
    
    Dim i As Integer
    
    
    If Len(sInput) > 8 Then
      IsComplex = True
    End If
    
    
    Test1:
    'numeric character
    If IsComplex Then
        For i = 1 To Len(sInput)
          If IsNumeric(Mid(sInput, i, 1)) Then
              GoTo Test2 'My apologies.
          End If
       Next
       IsComplex = False
    End If
    
    
    Test2:
    'non-numeric character
    If IsComplex Then
       For i = 1 To Len(sInput)
           If Not IsNumeric(sInput) Then
               GoTo Test3
           End If
       Next
       IsComplex = False
    End If
    
    
    Test3:
    'Upper case
    If IsComplex Then
        For i = 1 To Len(sInput)
          If StrComp(Mid(sInput, i, 1), LCase(Mid(sInput, i, 1)), vbBinaryCompare) <> 0 Then
              GoTo Test4
          End If
       Next
       IsComplex = False
    End If
    
    
    Test4:
    'lower case
    If IsComplex Then
       For i = 1 To Len(sInput)
           If StrComp(Mid(sInput, i, 1), LCase(Mid(sInput, i, 1)), vbBinaryCompare) = 0 Then
               GoTo ExitFunction
           End If
       Next
       IsComplex = False
    End If
    
    
    
    
    ExitFunction:
    End Function
    Cheers,
    Vlad

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Data validation on each row.
    By Homegrownandy in forum Forms
    Replies: 40
    Last Post: 05-22-2017, 02:31 AM
  2. Replies: 14
    Last Post: 01-07-2014, 04:20 PM
  3. Data Validation
    By Traci in forum Programming
    Replies: 1
    Last Post: 08-21-2012, 10:59 AM
  4. Data Validation using VBA
    By Cheshire101 in forum Programming
    Replies: 3
    Last Post: 05-10-2011, 08:43 AM
  5. Data Validation - Please help
    By larry S in forum Access
    Replies: 0
    Last Post: 11-16-2008, 10:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums