Results 1 to 5 of 5
  1. #1
    DHaedo is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2016
    Posts
    11

    Querying Three Joined Tables with Nulls

    Hi,
    I have been working on a creating a form for querying records from an external database source. All three tables have a unique ID "AAA-00000", table 1 has 4000 records with no duplicate ID's, table 2 8000 records with duplicates, table 3 has only 1000 records with no duplicates. I am cannot make the unique ID a primary key, but I can use it to link between the three tables. Using outer joins to link table 2 & 3 to table 1 yield the correct number of records. Once I add criteria to the the query it then limits the records to between the tables (using [Forms]![FrmA]![cboPick] for example).



    I have tried using in [Criteria] "Like IIf([Forms]![frmA]![cboPick]=" ","*",[Forms]![frmA]![cboPick])" and "Like "*" & [Forms]![frmA]![cboPick] & "*"" with wildcards (and other variations) but the criteria limits the records, and if I use "is Null" in the [Or] field it ignores the criteria.

    Can anyone help with the expression that will include Nulls?

    Thanks!

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    What field are you applying the criteria to?


    What does the value in [cboPick] look like, i.e. what table field value does it contain?

    How do you make the combo box contain a blank, rather than Null?

  3. #3
    DHaedo is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2016
    Posts
    11
    I am applying the criteria to a field called [StrGrade] (number field), this is in table 3 and only has the unique ID field (text) with the [StrGrade] field.

    The values in [cboPick] are based off another table with just the values [ ,1,2,3,4,5] as a Number field.

    To clear cboPick I have a "Clear" button that me.cboPick = "", I also have a master clear button for all the combo boxes that does the exact same function (me.cbo### = "") for all the combo boxes.

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Based on that, your criteria expression is way too complicated.

    The table field the combo box is based on contains numeric data; therefore each occurrence will contain either a number or Null - it cannot contain a blank or a zero-length string. So, that means the combo box value can only be a number or Null. Your comparisons with Like and wildcards don't mean anything.

    In your query, the values in [StrGrade] will equal the value in the combo box, or they will be Null. So two criteria cells for StrGrade. They are:

    [Forms]![frmA]![cboPick]
    Is Null

    Now, there is one big caveat to all that. The criteria cannot distinguish between a query row which has a record in table3 containing an ID value but no [strGrade] value (your data may not have any like that), and a query row which has no Table3 data at all (you're using an outer join).

    This should work for you.

  5. #5
    DHaedo is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2016
    Posts
    11
    Thanks John, I have redesigned part of my database to join the tables first (in sql), and then query on the table. I am still having issues with zero length fields from the joined table and the query. I am unable to convert zero length cells to nulls (or anything) while joining the tables. Any thoughts on converting zero length cells using sql code?
    Thanks

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

Similar Threads

  1. Link one table to 2 already joined tables
    By GabrielloG in forum Database Design
    Replies: 10
    Last Post: 12-17-2014, 05:00 PM
  2. Replies: 8
    Last Post: 06-04-2014, 10:01 AM
  3. Replies: 4
    Last Post: 03-10-2014, 06:16 AM
  4. Duplicate records in joined tables
    By msmithtlh in forum Programming
    Replies: 2
    Last Post: 04-10-2013, 08:19 AM
  5. Multiple Tables Joined ????
    By Ekim in forum Database Design
    Replies: 10
    Last Post: 01-15-2012, 07:08 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