Results 1 to 6 of 6
  1. #1
    securitywyrm is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    97

    Using IIF in an append query, invalid syntax

    I'm trying to use an append query that will help 'clean up' some inconsistent data I get on a gender flag. I get M, Male, F, Fem, Female, etc. So I'd like the append query when moving from the 'bad' data to my 'active' data to use an IIF command.


    The "bad" data field is called "Gender (M/F)", I can't change this.

    I tried this
    [EXPR3]=IIf([Gender (M/F)]=Like * & "F" & *,"Female","Male")
    But get an "invalid syntax" error. Any help on what I'm doing wrong would be helpful. The idea is that if the letter F is in the field, put female, otherwise put male.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Put the wildcards within the quotes, no equal sign with LIKE.

    IIf([Gender (M/F)] Like "*F*","Female","Male")

    Advise not to use spaces nor punctuation/special characters in naming convention.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    securitywyrm is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    97
    Quote Originally Posted by June7 View Post
    Put the wildcards within the quotes, no equal sign with LIKE.

    IIf([Gender (M/F)] Like "*F*","Female","Male")

    Advise not to use spaces nor punctuation/special characters in naming convention.

    Thank you!

    And indeed, I don't use spacing and punctuation in my naming conventions. That's why I'm importing the data from 'their' data tables to MY data tables.

  4. #4
    securitywyrm is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    97
    I also tried
    EXPR3: IIf([MasterRollupFile].[Gender (M/F)] Like "*F*","Female","Male")
    But it still prompts me for parameter value.

  5. #5
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I also tried
    EXPR3: IIf([MasterRollupFile].[Gender (M/F)] Like "*F*","Female","Male")
    But it still prompts me for parameter value.
    I set up these EXACT same structure, and it worked for without issue.

    If you are getting prompted, it means that it does NOT recognize your field name. Something is slightly different (it could be something as simple as an extra space).

    Please do the following.
    Create a real simple query, where you simply select (be sure to select it, not type it) this Gender field to display, and confirm that works.
    If it does (which it should), change the query to SQL View and copy and paste the code for that query here so we can see it.

  6. #6
    securitywyrm is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    97
    Quote Originally Posted by JoeM View Post
    I set up these EXACT same structure, and it worked for without issue.

    If you are getting prompted, it means that it does NOT recognize your field name. Something is slightly different (it could be something as simple as an extra space).

    Please do the following.
    Create a real simple query, where you simply select (be sure to select it, not type it) this Gender field to display, and confirm that works.
    If it does (which it should), change the query to SQL View and copy and paste the code for that query here so we can see it.
    Thank you, it was indeed a missing space.

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

Similar Threads

  1. Replies: 18
    Last Post: 02-26-2018, 03:42 PM
  2. VBA Syntax For Append Query
    By jo15765 in forum Programming
    Replies: 12
    Last Post: 04-10-2017, 10:39 AM
  3. Replies: 1
    Last Post: 01-17-2014, 03:06 PM
  4. Access 2007 Append Query Invalid Procedure Call
    By forrestapi in forum Queries
    Replies: 1
    Last Post: 05-13-2011, 07:53 AM
  5. Urgent: SQL Append Query Syntax
    By rushforth in forum Import/Export Data
    Replies: 14
    Last Post: 02-23-2011, 02:44 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