Results 1 to 13 of 13
  1. #1
    vit2016 is offline Novice
    Windows XP Access 2013 64bit
    Join Date
    Jul 2016
    Posts
    7

    Can I alter my expression so I don't have to manually enter zeros when either field 1 or 2 are blank

    Is it possible to alter my expression so I don't have to manually enter zeros when either field 1 or field 2 are blank?
    For example, in Field 1 there is nothing. In Field 2, there is 1. In Field 3, there is 650. The total reads nothing. If I manually enter a zero into Field 1, the total will read 650.
    Expression:
    Total: IIf([Table 1]![Field 1]+[Table 1]![Field 2]=0,Null,[Table 1]![Field 3]/([Table 1]![Field 1]+[Table 2]![Field 2]))


    I've tried making these changes, but it didn't work:

    Total: IIf (Nz([Table 1]![Field 1], 0)+Nz([Table 1]![Field 2], 0)=0,Null,[Table 1]![Field 3]/([Table 1]![Field 1]+[Table 1]![Field 2]))



    I am not very knowledgeable with access, so I don't know if this is possible. Thank you for your help.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    convert Nulls to Zero:

    nz([Table 1])+nz([Table 2])
    but it will NEVER be null, so you don't need the IIF.

  3. #3
    vit2016 is offline Novice
    Windows XP Access 2013 64bit
    Join Date
    Jul 2016
    Posts
    7
    Thank you for your help. Are you referring to the second part or the first?

    Total: IIf (Nz([Table 1]![Field 1], 0)+Nz([Table 1]![Field 2], 0)=0,Null,[Table 1]![Field 3]/([Table 1]![Field 1]+[Table 1]![Field 2]))

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    the entire IIF statement. If you NZ all your fields , no IIf is needed just:
    =NZ(Table 1]![Field 3]/(NZ([Table 1]![Field 1])+NZ([Table 1]![Field 2])))

  5. #5
    vit2016 is offline Novice
    Windows XP Access 2013 64bit
    Join Date
    Jul 2016
    Posts
    7
    Quote Originally Posted by ranman256 View Post
    the entire IIF statement. If you NZ all your fields , no IIf is needed just:
    =NZ(Table 1]![Field 3]/(NZ([Table 1]![Field 1])+NZ([Table 1]![Field 2])))
    If I do that, I receive #Num! and #Div/0! errors

    Total: Nz([Table 1]![Field 3],0)/Nz([Table 1]![Field 1],0)+Nz([Table 1]![Field 2],0)

  6. #6
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,045
    Try
    IIf (Nz([Table 1]![Field 1], 0)+Nz([Table 1]![Field 2], 0)=0,Null,[Table 1]![Field 3]/(NZ([Table 1]![Field 1],0)+NZ([Table 1]![Field 2],0)))

  7. #7
    vit2016 is offline Novice
    Windows XP Access 2013 64bit
    Join Date
    Jul 2016
    Posts
    7
    The same problem happened

    Quote Originally Posted by vit2016 View Post
    If I do that, I receive #Num! and #Div/0! errors

    Total: Nz([Table 1]![Field 3],0)/Nz([Table 1]![Field 1],0)+Nz([Table 1]![Field 2],0)
    Edit: Quote added
    Last edited by vit2016; 07-07-2016 at 01:24 PM.

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    How about describing WHAT you are trying to do, rather than how you have done something that isn't working?
    Experienced people have offered suggestions and
    The same problem happened
    so I think we need to hear the requirement clearly in simple terms, and then see if some options follow.

  9. #9
    vit2016 is offline Novice
    Windows XP Access 2013 64bit
    Join Date
    Jul 2016
    Posts
    7
    I explain in my earlier posts.

    Is it possible to alter my expression so I don't have to manually enter zeros when either field 1 or field 2 are blank?
    For example, in Field 1 there is nothing. In Field 2, there is 1. In Field 3, there is 650. The total reads nothing. If I manually enter a zero into Field 1, the total will read 650.
    Expression:
    Total: IIf([Table 1]![Field 1]+[Table 1]![Field 2]=0,Null,[Table 1]![Field 3]/([Table 1]![Field 1]+[Table 2]![Field 2]))


    I've tried making these changes, but it didn't work:

    Total: IIf (Nz([Table 1]![Field 1], 0)+Nz([Table 1]![Field 2], 0)=0,Null,[Table 1]![Field 3]/([Table 1]![Field 1]+[Table 1]![Field 2]))

    I am not very knowledgeable with access, so I don't know if this is possible. Thank you for your help.

    ---

    If I do that, I receive #Num! and #Div/0! errors

    Total: Nz([Table 1]![Field 3],0)/Nz([Table 1]![Field 1],0)+Nz([Table 1]![Field 2],0)

  10. #10
    vit2016 is offline Novice
    Windows XP Access 2013 64bit
    Join Date
    Jul 2016
    Posts
    7
    Quote Originally Posted by orange View Post
    How about describing WHAT you are trying to do, rather than how you have done something that isn't working?
    Experienced people have offered suggestions and
    so I think we need to hear the requirement clearly in simple terms, and then see if some options follow.


    I appreciate the help. I now added the quote in my response after a bit of a struggle. I am not good at using message boards. I did not mean to post twice (this and above). Please don't misunderstand. Thank you.

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Sorry, but your first post only shows us something that you have done
    Total: IIf([Table 1]![Field 1]+[Table 1]![Field 2]=0,Null,[Table 1]![Field 3]/([Table 1]![Field 1]+[Table 2]![Field 2]))

    WHAT is it - in plain simple English - you are trying to solve using that expression?

    What are table1 and table2
    ?

    Since you are getting
    If I do that, I receive #Num! and #Div/0! errors
    ,
    there is an error somewhere in your table(s), your expression.
    Division by 0 is an absolute No-No! which indicates ([Table 1]![Field 1]+[Table 2]![Field 2]) is rendered as 0.??????

    We need to understand the problem you are trying to solve.
    Good luck.

  12. #12
    vit2016 is offline Novice
    Windows XP Access 2013 64bit
    Join Date
    Jul 2016
    Posts
    7
    Quote Originally Posted by orange View Post
    Sorry, but your first post only shows us something that you have done


    WHAT is it - in plain simple English - you are trying to solve using that expression?

    What are table1 and table2
    ?

    Since you are getting
    ,
    there is an error somewhere in your table(s), your expression.

    We need to understand the problem you are trying to solve.
    Good luck.
    I am sorry I thought by what I am trying to achieve you are referring to this. Honest miscommunication

    "Is it possible to alter my expression so I don't have to manually enter zeros when either field 1 or field 2 are blank?"

    I want to find cost per use. Field 1 and Field 2 are the item uses. Field 3 is the cost. Some items are not used, and some items don't have a cost. Thanks for your help. Thank you

  13. #13
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    So is Table2 a mistake in your expression in post 1?

    Working with the expression from NoellaG:
    IIf (Nz([Table 1]![Field 1], 0)+Nz([Table 1]![Field 2], 0)=0,Null,[Table 1]![Field 3]/(NZ([Table 1]![Field 1],0)+NZ([Table 1]![Field 2],0)))

    If there is only table1, then you do not need the reference to Table1. And you wouldn't refer to a field in a table with "!", so

    IIf (Nz([Field 1], 0)+Nz([Field 2], 0)=0,Null,[Field 3]/(NZ([Field 1],0)+NZ([Field 2],0))) and I would add another pair of brackets


    Code:
    TRY:
    Total: IIf (Nz([Field 1], 0)+Nz([Field 2], 0)=0,Null,([Field 3]/(NZ([Field 1],0)+NZ([Field 2],0))))
    But what are the datatypes of [Field 1], [field 2] and [field 3]?

    Can you take a Printscreen of your table and its values? Post as a jpg

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

Similar Threads

  1. Alter Table, YES/NO field
    By gmaster in forum Queries
    Replies: 1
    Last Post: 10-29-2014, 03:25 AM
  2. Replies: 3
    Last Post: 08-15-2013, 02:52 PM
  3. enter ID automatically or manually
    By msasan1367 in forum Access
    Replies: 3
    Last Post: 06-03-2013, 10:21 AM
  4. Replies: 7
    Last Post: 09-06-2012, 06:04 AM
  5. Alter table Yes/No field
    By Cojack in forum Queries
    Replies: 7
    Last Post: 10-27-2010, 11:31 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