Results 1 to 5 of 5
  1. #1
    databasewolfy is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2019
    Posts
    10

    calculated fields with multiple tables

    Hey there. I'm a bit of a newbie to SQL statements, let alone programming.



    I have a database with three tables. I want a column to return three values based on three conditions.


    Table1
    name

    Table2
    name

    Table3
    name
    foo (calculated field)


    Table1.name and Table2.name can never match.
    If Table3.name has an entry that matches in Table1.name, then foo = X
    If Table3.name has an entry that matches in Table2.name, then foo = Y
    If Table3.name does not have an entry that matches in either table, then foo = not found


    As far as forms go, can this statement be applied to a control box to just display the appropriate value?

    Thanks in advance.

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,935
    in a query left join table 3 to tables 1 and 2 on name

    calculated value would be switch(nz(table1.name,"")<>"","X",nz(table2.name," ")<>"","Y",True,"not found")

    note that options for calculated values in tables are very limited, certainly what you require cannot be done in a table, only in a query

    As far as forms go, can this statement be applied to a control box to just display the appropriate value?
    you can apply the above formula to the controlsource of a form or report control or simply include in the form/report recordsource. As a controlsource your form/report recordsource would need to include table1.name and table2.name. As part of the recordsource you would just need to bring through the formula result

  3. #3
    databasewolfy is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2019
    Posts
    10
    Quote Originally Posted by Ajax View Post
    in a query left join table 3 to tables 1 and 2 on name

    calculated value would be switch(nz(table1.name,"")<>"","X",nz(table2.name," ")<>"","Y",True,"not found")

    note that options for calculated values in tables are very limited, certainly what you require cannot be done in a table, only in a query

    you can apply the above formula to the controlsource of a form or report control or simply include in the form/report recordsource. As a controlsource your form/report recordsource would need to include table1.name and table2.name. As part of the recordsource you would just need to bring through the formula result
    I'm afraid I don't understand what you mean by "left join"

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,935
    when you create a query, you join the different tables together

    once you have done this, right click on the join line and select the option 'include all records from table 3 and only those records from table 1 where there is a match'

  5. #5
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    This article explains the different types of query join with examples http://www.mendipdatasystems.co.uk/q...pes/4594517491
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

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

Similar Threads

  1. Calculated Fields from Multiple Tables
    By dccjr3927 in forum Programming
    Replies: 2
    Last Post: 04-23-2019, 02:26 PM
  2. Creating calculated fields from different tables
    By Brownie1987 in forum Access
    Replies: 6
    Last Post: 01-15-2018, 01:37 PM
  3. Replies: 1
    Last Post: 04-12-2017, 07:39 AM
  4. Replies: 1
    Last Post: 03-14-2016, 06:44 PM
  5. Calculated Fields in tables
    By dharsh in forum Misc
    Replies: 12
    Last Post: 07-01-2013, 03:07 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