Results 1 to 4 of 4
  1. #1
    jenn is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Sep 2016
    Posts
    2

    Lightbulb Help with Expression/Criteria using the LIKE function with fieldnames and wildcards (Query)


    I am trying to compare two columns in Access with a query and show when they don't match. The first column is called Sheet1.lastname and the 2nd column is called Sheet2.fullname.
    Sheet1.lastname
    Smith
    Brown
    Jones

    Sheet2.fullname
    Smith,George
    Brown, Juliette
    OtherPerson, John

    I would like to change the criteria on the 2nd column so that it looks for the lastname value within the fullname column.

    The SQL script looks like this:
    Where ([Sheet2].[fullname]) Not Like [Sheet1].[lastname])); --> that only seems to function properly when the values are exactly the same, when I try to add the * wildcard for this:

    Where ([Sheet2].[fullname]) Not Like [Sheet1].[lastname]*)); - I get a function error.

    Any suggestions on how I can accomplish this?

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Not Like "*" & [Sheet1].[lastname] & "*"

    That surrounds the field with wild cards, saying anything in front of the search and anything behind it. It is called string concatenation, making up what you want with quotes and &'s until it comes out looking how you want it.

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I am trying to compare two columns in Access with a query and show when they don't match
    If I understand correctly I would do this a little different.

    Obviously, this isn't real data because trying to show names that don't match using only last names will not give you good results - Smith, John and Smith, Jim would match but they are different people.


    Anyway, first create a query named "qrySheet1".
    SQL would be
    Code:
    SELECT lastname FROM Sheet1;
    Second, create a query named "qrySheet2".
    SQL would be
    Code:
    SELECT IIf(InStr([fullname],",")>0,Left([fullname],InStr([fullname],",")-1),[fullname]) AS lastname FROM Sheet2;

    Last, use the Query wizard to create an unmatched query. The SQL would look like:
    Code:
    SELECT qrySheet2.lastname
    FROM qrySheet2 LEFT JOIN qrySheet1 ON qrySheet2.[lastname] = qrySheet1.[lastname]
    WHERE (((qrySheet1.lastname) Is Null));

  4. #4
    jenn is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Sep 2016
    Posts
    2

    Thank you!

    Quote Originally Posted by aytee111 View Post
    Not Like "*" & [Sheet1].[lastname] & "*"

    That surrounds the field with wild cards, saying anything in front of the search and anything behind it. It is called string concatenation, making up what you want with quotes and &'s until it comes out looking how you want it.

    **perfect - that is what I was missing!

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

Similar Threads

  1. Criteria part in an expression in a query.
    By Perfac in forum Queries
    Replies: 1
    Last Post: 05-18-2016, 11:48 AM
  2. Conditional Formatting - Using Eval function with wildcards
    By mlichtenstein in forum Programming
    Replies: 2
    Last Post: 07-02-2015, 08:09 AM
  3. Query Criteria Expression
    By Ranger7913 in forum Queries
    Replies: 3
    Last Post: 11-17-2014, 09:49 AM
  4. Replies: 1
    Last Post: 11-13-2014, 11:34 PM
  5. Replies: 1
    Last Post: 12-30-2012, 07:57 PM

Tags for this Thread

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