Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Posts
    989
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Prevent division by zero (2003)

    I believe there is an alternative to an expression like 'iif([SomeNo]=0,"n/a",[OtherNo]/[SomeNo])' that will correctly avoid a division by zero error. I believe the quoted expression can still create this error because Access parses the whole expression. Does anyone know a valid alternative? Thanks, Andy.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Prevent division by zero (2003)

    It depends where you want to use it. In VBA code, you get the behavior you describe, so you should use If ... Then ... Else ... End If instead of IIf.
    In expressions in a query or in the control source of a control on a form or report, the problem doesn't occur - if the condition is True, only the TruePart is evaluated, not the FalsePart.

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Posts
    989
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Prevent division by zero (2003)

    Thank you. Although the expression seemed to work within a query I thought it still parsed it and might create problems further down the line.. Andy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •