Results 1 to 7 of 7
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371

    Checking If Yes/No Field Is Null

    Hi Guy's What is the method of checking if yes/no field is null

    is it
    if = 0
    if is null


    if = nothing

    ???

    Code:
     curTotal = DSum("Price", "tblInvoices", "[Customer] = '" & strCust & "'")            curPaid = DSum("Price", "tblInvoices", "[Customer] = '" & strCust & "' And Paid = Yes")
                
                If curUnpaid = DSum("Price", "tblInvoices", "[Customer] = '" & strCust & "' And Paid = No") = 0 Then
                curUnpaid = "00.00"
                Else
                curUnpaid = DSum("Price", "tblInvoices", "[Customer] = '" & strCust & "' And Paid = No")
                End If

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    A yes/no data type field is never null. It is either -1 or 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.

  3. #3
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Thanks June7 so would i remove the where i have highlighted red and change

    and Paid = 0 instead of No ?

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    in a query:
    where [field] is null


    in forms:
    if IsNull(txtBox) then

    but yes, boolean fields are not null.

  5. #5
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Got it June7, thank you, changed to If Is Null, this appeared to have worked ok

    Code:
    If IsNull(curUnpaid = DSum("Price", "tblInvoices", "[Customer] = '" & strCust & "' And Paid = No")) Then            curUnpaid = "00.00"
                Else
                curUnpaid = DSum("Price", "tblInvoices", "[Customer] = '" & strCust & "' And Paid = No")End If

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Simplify, eliminate the If Then and the repeated DSum:

    curUnpaid = Nz(DSum("Price", "tblInvoices", "[Customer] = '" & strCust & "' And Paid = No"), 0)

    Why would you set curUnpaid to a string? Instead of using Customer why not the Customer ID?
    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
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,426
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 3
    Last Post: 08-20-2020, 05:38 PM
  2. Error checking for Null value in IF EndIf statement
    By Cottonshirt in forum Modules
    Replies: 10
    Last Post: 02-13-2018, 12:08 AM
  3. Replies: 3
    Last Post: 06-30-2017, 10:56 AM
  4. Replies: 7
    Last Post: 11-07-2016, 09:24 AM
  5. Problem checking for Null Value of a Textbox.
    By SIGMA248 in forum Programming
    Replies: 3
    Last Post: 08-09-2010, 08:56 AM

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