Results 1 to 6 of 6
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097

    Validate a string with a mask


    Is there a simple way to compare a string to a mask? I tried something like if me.JOINEDGRP <> Like "L000", but the compiler didn't like that. I'm looking for strings like "F2024".

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,935
    See this link for using wildcards
    https://support.microsoft.com/en-us/...0-242cde582e0b

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,558
    Or just use the logic?
    Code:
    Sub NotLike()
    Dim strInput As String, strWord As String
    
    
    strWord = "David Gilmour"
    strInput = InputBox("Name")
    strInput = strInput & "*"
    If strWord Like strInput Then
        MSGBOX "input is like"
    Else
        MSGBOX "input is not like"
    End If
    
    
    
    
    End Sub
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    Looking at your code, I don't understand why
    if me.JOINEDGRP <> Like "S####" then
    won't work? Where I'm checking for a string like "S2024"

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,558
    I thought you had already discovered that <> Like does not work?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    Well, I didn't have the wild characters correct. Again, if your "If strWord Like strInput Then" compiles correctly, why wouldn't my use of the "S####" as the mask work? It's just a string like your strInput?

    I'M A DUMMY! I wasn't thinking of "Like" as being an Operator. I simply needed to rid the statement of the extraneous "<>".

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

Similar Threads

  1. Replies: 13
    Last Post: 08-14-2021, 04:53 AM
  2. Best way to validate
    By Fairportjay in forum Forms
    Replies: 2
    Last Post: 05-06-2019, 11:45 AM
  3. Validate Dates
    By pervezjan in forum Access
    Replies: 1
    Last Post: 07-07-2015, 10:46 AM
  4. Validate with code Yes or No
    By GinaFlan in forum Forms
    Replies: 10
    Last Post: 10-06-2014, 08:10 PM
  5. Validate a field
    By tweety in forum Forms
    Replies: 19
    Last Post: 03-29-2013, 04:06 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