Results 1 to 3 of 3
  1. #1
    jyellis is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    20

    Syntax error with Wildcard ? in a query expression


    IIf([User Id]=”1???????”,[User ID], IIf([User Id]=”C??????”,[User ID],IIf([User ID]=”No User ID”,””)))

    I get a syntax error on the first question mark.

    If the length=8 and begins with a 1, then [User ID]
    If the length =7 and begins with a C, then [User ID],
    if the field contains "No User ID", then return nothing.

    I have more criteria but that part works; it's just this first part.

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Try a structure like:
    Code:
    IIF((Left([User iD],1)="1") And (Len([User Id])=8),[User Id],...
    For the next check (length 7, starting with "C"), you could nest it like you were, or combine it with the first one using OR.

  3. #3
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Also check your quotation marks. If that's what you really have, I have seen this cause problems before (backwards or forwards leaning quotes).
    if the field contains "No User ID", then return nothing.
    OK, this isn't the cause of the error, but might raise an issue soon. "" is not "nothing". Nor is it Null. So your query might not function properly if the empty string you're passing to it comes in to play.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Syntax error in query expression
    By ittiekat in forum Queries
    Replies: 6
    Last Post: 02-11-2016, 05:39 PM
  2. Replies: 2
    Last Post: 09-10-2014, 11:30 AM
  3. Replies: 11
    Last Post: 05-01-2014, 11:56 AM
  4. Replies: 3
    Last Post: 03-05-2013, 11:17 AM
  5. Replies: 6
    Last Post: 05-30-2012, 12:32 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