Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544

    Can't query properly on yes/no field

    I am simply trying to query Posted=false. Have tried posted=0 and posted <>true and posted <>-1. What I'm trying to show is: in a subform on the Inventory form I want to show any products that are still open on a Purchase Order, linked by product number. The sql behind the subform



    Code:
    SELECT DISTINCT PODetails.DetailID, PODetails.PO, InventoryReceiving.QtyReceived, PODetails.Productnumber, PODetails.QTYOrdered, PODetails.ETA, PODetails.DateReceived, PODetails.RecYN, PODetails.Description, InventoryTransactions.Posted
    FROM (PODetails LEFT JOIN InventoryReceiving ON PODetails.PO = InventoryReceiving.PurchaseOrder) LEFT JOIN InventoryTransactions ON PODetails.Productnumber = InventoryTransactions.ProductNumber
    WHERE (((InventoryTransactions.Posted)<>-1));
    Click image for larger version. 

Name:	invyesnoissue.PNG 
Views:	24 
Size:	22.0 KB 
ID:	39229 This product should show up on the subform. I have verified the data is correct in all tables. I've tried to filter by form as well, with the same results (nothing).

    I feel like I'm missing something really simple. But now I've worked myself into a tizzy.

    Thoughts? thanks in advance!

  2. #2
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,180
    Hi,

    first leave out the WHERE clause on your SQL. If still no records show there must be something wrong in your joins. If the record shows up: check the field Posted. Is it a Yes/No field or a numeric or even a text field. Does it contain NULL values?

    Kind regards
    Noëlla

  3. #3
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Thank you Noella! It is a yes/no field. If I use no criteria (where) I get all of the records as expected. When viewing the results, I can filter for selected or cleared. there are no null values that I know of, just selected or cleared (yes or no)

  4. #4
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,180
    I see you show the lines in a subform, can you check the link master/child field of the subform object?

  5. #5
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,180
    or try
    WHERE not(
    InventoryTransactions.Posted)

  6. #6
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Ohhhh, I thought you were onto something clever with that where statement, but sadly, it didn't produce the results I need. My subform and main form are linked by product number...I do think my joins have something to do with it....I just haven't been able to untangle them this morning. Thank you for your help Noella!

  7. #7
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Click image for larger version. 

Name:	invtransissues.PNG 
Views:	22 
Size:	20.4 KB 
ID:	39230
    I think because until a product has been checked in as 'received' in Purchase Orders it doesn't get added to the inventory transactions table, and even though I have it setup to include all products on PO, and only those that match from received and transaction tables, its not correct for me to ask it what I am. I think.

  8. #8
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    The correct filter clause would just be Posted =False.
    I think the issue is you have left joins and the Posted field is on the 'receiving end' of the join arrow.
    Also the two inventory tables don't have a primary key field which could be an issue.
    Suggest the two ID fields are made primary keys.

    As a test, try the same query with two inner joins. Does that work?
    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!

  9. #9
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    try a criteria of

    <>-1 or is null

    if you added the field after the fact or it does not have a default value of 0 (false) in the table design you can't get it without checking for null as well

    EDIT
    your yes/no has 3 distinct states

    True
    False
    Null

    For your purposes FALSE and NULL are the same thing

  10. #10
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Unlike in SQL Server where Boolean fields can also be null, boolean fields in Access can only be true or false.
    So unless this is a split database with linked sql tables, I disagree with the previous answer.
    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!

  11. #11
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    the user is using a left join to the table with the yes/no field, if he/she wants the record to appear where there is no value he/she must include a check for null.

    Example

    T_ID TestYesNo
    1 No
    2 Yes

    TID
    1
    2
    3

    Query
    Code:
    SELECT Table2.TID, Table1.TestYesNoFROM Table2 LEFT JOIN Table1 ON Table2.TID = Table1.T_ID
    WHERE (((Table1.TestYesNo)<>-1));
    will produce 1 record, record 1

    Query
    Code:
    SELECT Table2.TID, Table1.TestYesNo
    FROM Table2 LEFT JOIN Table1 ON Table2.TID = Table1.T_ID
    WHERE (((Table1.TestYesNo)<>-1 Or (Table1.TestYesNo) Is Null));
    will produce 2 records, 1 and 3

  12. #12
    GinaWhipp's Avatar
    GinaWhipp is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Jul 2011
    Location
    Ohio, USA
    Posts
    377
    Hmm, actually you can have NULL in an Access query if you have records on the one side that do not have records on the many said and not using an INNER join, real pain. Good news is they shouldn't show hen filtering on Yes\No. On SQL Server, BIT fields need a default value or you won't be able to update the table. I said all that to say you need to flip between True\False Or Is NULL

  13. #13
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    I accept the reasoning in the last two posts but my comment regarding boolean fields in Access was correct.

    As an aside, false is always zero. True is any value other than zero but Access will change it to -1.
    That's why I said to use Posted=False though Posted=0 works just as well
    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!

  14. #14
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,935
    @Colin

    Unless I'm missing the point, boolean fields can be null in access - just don't provide a default value of true or false. You can also set a triple state with a checkbox or option control on a form or report (but not in table design) where the third state is null.

    my two penneth for the criteria would be

    WHERE nz(Posted,false)=false

    or

    WHERE not nz(Posted,false)

  15. #15
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Quote Originally Posted by Ajax View Post
    @Colin

    Unless I'm missing the point, boolean fields can be null in access - just don't provide a default value of true or false. You can also set a triple state with a checkbox or option control on a form or report (but not in table design) where the third state is null.
    Hi Ajax
    Yes I think you may be missing the point
    Any boolean fields left blank in Access are FALSE
    See https://sourcedaddy.com/ms-access/boolean-data.html

    You can indeed have a triple state checkbox which is NULL (grey shaded) but ONLY for unbound controls.
    If you try doing that for bound controls it doesn't work

    In SQL Server, and many other database applications, boolean fields can be null unless you specify otherwise.
    In such cases, if no default value is set, when the sql server table is linked to Access issues arise when an update query is run on any records with null booleans
    Access is unable to handle the nulls and throws a write conflict error

    For example, see https://www.access-programmers.co.uk...t+boolean+null and https://www.access-programmers.co.uk...t+boolean+null
    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!

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 04-25-2017, 12:22 AM
  2. Replies: 5
    Last Post: 01-23-2015, 03:38 PM
  3. Selecting TOP 3 in one field is not working properly
    By Access_Novice in forum Queries
    Replies: 5
    Last Post: 12-27-2014, 07:34 PM
  4. How to display RTF field properly in Access Query
    By Linda1234 in forum Code Repository
    Replies: 0
    Last Post: 09-26-2012, 12:43 PM
  5. Form Field Not Calculating Properly
    By RMittelman in forum Forms
    Replies: 3
    Last Post: 07-25-2012, 01:05 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