Results 1 to 5 of 5
  1. #1
    Tzames is offline Novice
    Windows XP Access 2013
    Join Date
    Aug 2015
    Posts
    2

    Talking Trouble writing a query that combines two fields if criteria is met

    Hi AccessForums.net,



    I'm writing a query that takes data from a spreadsheet and puts it into a format that is more easily read and combines data from certain fields to arrive at a final number (needed for accounting purposes). My final number depends on what currency, what exchange, and what form the data derives from. Currently, my work-in-progress attempts look like
    IIf(([Exchange Name]=[IMF Rates]) And ([Exchange Name]=[IMF]),[Spread Sorted (IMF)]![Excess/Deficit]+[Spread Sorted (IMF Rates)]![Excess/Deficit], FALSE)
    Expr1: IIf(([Collateral Statement]![Exchange Name]="IMF Rates") And ([Collateral Statement]![Exchange Name]="IMF") And ([Collateral Statement]![Currency Basis]="Collateral Ccy") And ([Collateral Statement]![Currency]="USD"),0,999)


    (Ignore the true/false parts. That's just a placeholder until I figure out what's wrong with the language)

    Basically none of these work and I'm having a hard time figuring out why. Microsoft access alludes to the problem being because I'm pulling the Exchange Name part from multiple tables, which I don't think is true. Also I want the query to return the data even if its not from both exchanges it.

    I want the data to add if it is part of "IMF Rates" and "IMF", but I also want the data returned if its part of either or, not both.

    Tell me what I'm doing wrong; I'm a beginner w/ no previous experience and I've no idea how to fix hah.

    Thanks!

    Tzames

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Post the entire query SQL statement. In order for expression to reference tables, tables must be included in the query design.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    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
    Tzames is offline Novice
    Windows XP Access 2013
    Join Date
    Aug 2015
    Posts
    2
    SELECT [Spread Sorted (IMF)].[COB Date], [Spread Sorted (IMF)].[Broker Account], [Spread Sorted (IMF)].[Our Account],
    Expr1: IIf(([Collateral Statement]![Exchange Name]="IMF Rates") And ([Collateral Statement]![Exchange Name]="IMF") And ([Collateral Statement]![Currency Basis]="Collateral Ccy") And ([Collateral Statement]![Currency]="USD"),0,999)
    FROM [Spread Sorted (IMF)] INNER JOIN [Spread Sorted (IMF Rates)] ON ([Spread Sorted (IMF)].[Our Account] = [Spread Sorted (IMF Rates)].[Our Account]) AND ([Spread Sorted (IMF)].[Broker Account] = [Spread Sorted (IMF Rates)].[Broker Account]) AND ([Spread Sorted (IMF)].[COB Date] = [Spread Sorted (IMF Rates)].[COB Date]);

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Table [Collateral Statement] is not included in the query therefore cannot reference its fields in IIf() expression.

    Does that table have a relationship with [Spread Sorted (IMF)] or [Spread Sorted (IMF Rates)]?

    Advise no spaces or special characters/punctuation (underscore is exception) 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.

  5. #5
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    In post #3 you have this:

    IIf(([Collateral Statement]![Exchange Name]="IMF Rates") And ([Collateral Statement]![Exchange Name]="IMF").....

    That doesn't make any sense - you are asking [Exchange Name] to be equal to two different values at the same time - it will never be true. It's like saying

    If (A=1 and A=2) then ... do something.

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

Similar Threads

  1. Writing Formula in query on existing fields
    By Esmatullaharifi in forum Queries
    Replies: 1
    Last Post: 04-14-2015, 07:29 AM
  2. Replies: 7
    Last Post: 02-06-2015, 01:08 PM
  3. Replies: 16
    Last Post: 12-08-2012, 07:44 AM
  4. Replies: 1
    Last Post: 05-30-2011, 06:03 PM
  5. Writing between criteria in a form
    By Suzied in forum Forms
    Replies: 7
    Last Post: 03-26-2010, 12:41 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