Results 1 to 8 of 8
  1. #1
    emspence is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2013
    Posts
    5

    Comparing Columns of numbers with IIf function


    I have 2 sets of numbers five columns each set each number in seperate column. I want to compare the numbers in the second set to the numbers in the first set. If they match the result is 1, if not 0. First set columns named field 1 thru field 5. Second set of numbers named F3 thru F7. So essentially I want to compare F3 against Fields 1 thru 5. If it matches either field result would be 1. I keep getting syntax. So I tried to do the same with individual columns but thats a lot of unnecessary calculations I think. Thanks in advance for any help.
    Last edited by emspence; 02-21-2013 at 06:26 PM.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    What do you want?

    If any of fields 1 thru 5 match any of F3 thru F7 then TRUE?
    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
    emspence is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2013
    Posts
    5
    yes that is exactly what i am trying to get. And true equals 1, false equals 0. Unfortunately I keep getting syntax.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Well, does sound like it would be a very long nested IIf expression. Probably want to build a custom function in VBA and call the function from query or textbox.

    Show the expression you have attempted.
    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.

  5. #5
    emspence is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2013
    Posts
    5
    I tried many different so I cannot show exactly what you're asking for, but at current I have: NM1A: IIf([F3]=[Field1],1,0) That only compares F3 against Field 1, so I have to do this 4 more times, 1 for each field and them sum all 5 fields. And then I would have to repeat for F4 through F7. I know this is Access and not Excel but I have done this in Excel and it works there with an If statement. But I cannot automate steps after this in Excel, so I really need to get this working here. Of course once I get this comparing working then I can filter out all the results that are zero and reduce the number of records that my query is retrieving. Right now it is somewhere around 44 million records which are causing me some "not responding" issues. Thank you some much for your help.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Why would you need to do sum?

    Is this what you are looking for:

    IIf([F3]=[Field1] Or [F3]=[Field2] Or [F3]=[Field3] Or [F3]=[Field4] Or [F3]=[Field5] Or
    [F4]=[Field1] Or [F4]=[Field2] Or [F4]=[Field3] Or [F4]=[Field4] Or [F4]=[Field5] Or
    [F5]=[Field1] Or [F5]=[Field2] Or [F5]=[Field3] Or [F5]=[Field4] Or [F5]=[Field5] Or
    [F6]=[Field1] Or [F6]=[Field2] Or [F6]=[Field3] Or [F6]=[Field4] Or [F6]=[Field5] Or
    [F7]=[Field1] Or [F7]=[Field2] Or [F7]=[Field3] Or [F7]=[Field4] Or [F7]=[Field5], 1, 0)
    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.

  7. #7
    emspence is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2013
    Posts
    5
    i will try what you show, but I will need to sum the 5 results fields i.e reults of F3 against Fields 1 thru 5, the the results of F4 against fields 1 thru 5, etc...., but I was not using "Or" in between, so hopefully that was my issue. Again thanks very much.

  8. #8
    emspence is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2013
    Posts
    5
    Okay it worked. Thank you. Such a simple solution. Well I won't have to worry about paying for a haircut anytime soon.

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

Similar Threads

  1. Replies: 2
    Last Post: 05-17-2012, 03:52 PM
  2. Replies: 1
    Last Post: 11-29-2011, 08:43 AM
  3. Function comparing rows
    By Dharmesh in forum Access
    Replies: 1
    Last Post: 10-20-2011, 07:59 AM
  4. Comparing 2 columns against 2 other columns
    By Amadeus in forum Access
    Replies: 4
    Last Post: 06-09-2011, 02:48 PM
  5. Getting wrong answer when comparing numbers
    By cowboy in forum Queries
    Replies: 7
    Last Post: 05-18-2010, 01:42 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