Results 1 to 6 of 6
  1. #1
    fishhead is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2015
    Posts
    167

    how to handle a null field

    Can someone tell me how to add two fields together when one of them is null?



    I'm looking to calculate my profit from my buy and sell fields
    some buy fields will be empty (null) and this seems to prevent me from using the following expression in my query GP=[sell]-[buy]

    As long as there is a value in the buy field (even if the value is "0") the expression works well. unfortunately i can't update date all the null records to 0

    is there a work around?

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    GP=Nz([sell],0)-Nz([buy],0)
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    GP=Nz([sell],0)-Nz([buy],0)

    Or more correctly, as a calculated field it would be:
    GP:Nz([sell],0)-Nz([buy],0)
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    fishhead is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2015
    Posts
    167
    Great thanks!

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Quote Originally Posted by fishhead View Post
    Great thanks!
    You're welcome. Glad to help
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  6. #6
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    I use NZZ(field):

    Code:
    Public Function Nzz(ByVal pvAmt)
    On Error Resume Next
    Nzz = Val(Nz(pvAmt, 0))
    End Function
    


    save on those stupid zeros.

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

Similar Threads

  1. Replies: 3
    Last Post: 12-09-2019, 03:28 PM
  2. Replies: 7
    Last Post: 11-07-2016, 09:24 AM
  3. Field that can handle addition
    By albzn in forum Forms
    Replies: 15
    Last Post: 10-06-2015, 01:35 PM
  4. How to handle null in SQL statement
    By ultimateguy in forum Programming
    Replies: 21
    Last Post: 08-15-2014, 10:48 AM
  5. Replies: 2
    Last Post: 11-19-2012, 05:42 PM

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