Results 1 to 4 of 4
  1. #1
    thorwood is offline Novice
    Windows 98/ME Access 2003
    Join Date
    May 2011
    Posts
    2

    Division by zero error on a query

    Hi



    I'm new to the forum, and new to Access in general really.

    I have the following query, but receive a "division by zero" error if LY_PICKUP is zero. So, I'd like to always return a value of 1 if LY_PICKUP is zero, as it does if it encounters a "null"....but not sure how to do it!

    PICKUP: Round(IIf([LY_PICKUP] Is Null,IIf([VAR_PICKUP]<0,-1,1),[VAR_PICKUP]/[LY_PICKUP]),4)

    Any assistance is appreciated

    Thanks

    Tim

  2. #2
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,043
    Hi

    try the NZ function:
    NZ([myValue],value if myValue is null)

    example:
    NZ([LY_PICKUP],1)
    will return 1 if [LY_PIckup] is null; the value of [LY_PICKUP] if not null

    greetings
    NG

  3. #3
    thorwood is offline Novice
    Windows 98/ME Access 2003
    Join Date
    May 2011
    Posts
    2
    Hi Noella

    Thanks for the reply, but the only thing is that I don't mind a response of "null". It's a response of "0" that I don't want, because I cannot then divide by zero.

    Ideally, I'd want to put something in that implies if [LY_PICKUP] is "null" OR "0" then return "1"..... ?

    Thanks

    Tim

  4. #4
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,043
    Hi,

    have you tried:
    iif([LY_PICKUP] = 0,1,NZ([LY_PICKUP],1))
    ?

    greetings
    NG

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

Similar Threads

  1. Query Error
    By Cined in forum Queries
    Replies: 3
    Last Post: 03-05-2011, 07:20 PM
  2. Replies: 10
    Last Post: 02-02-2011, 05:48 PM
  3. append query error
    By shashigk in forum Queries
    Replies: 2
    Last Post: 09-22-2009, 07:17 AM
  4. Inconsistent Query Error...
    By DHavokD in forum Queries
    Replies: 8
    Last Post: 06-11-2009, 09:58 AM
  5. Query Error
    By zephaneas in forum Queries
    Replies: 0
    Last Post: 11-12-2008, 02:40 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