IFERROR function equivalent in Access (2 Viewers)

Isaac

Lifelong Learner
Local time
Yesterday, 19:08
Joined
Mar 14, 2017
Messages
8,792
I don't see the right parenthesis on the OP's most recent post at all..
You have it in red bold at the end of yours, but it's not there on the end of theirs..
test.jpg
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 19:08
Joined
Aug 30, 2003
Messages
36,129
Is there a way to add an OR type statement to this? Something along the lines of =IIf(nz([txtAction2s],0)=0 OR nz([txtAction1s],0)=0 ,null,[txtAction1s]/[txtAction2s].

There is no closing parentheses to the IIf()
 
Last edited:

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 19:08
Joined
Aug 30, 2003
Messages
36,129
Oops, didn't see there was a page 2.
 

strive4peace

AWF VIP
Local time
Yesterday, 21:08
Joined
Apr 3, 2020
Messages
1,002
adding on ...

if there is an error, try this for the expression:
[txtAction1s] / nz( [txtAction2s],1 ) *100​

because both arguments for IIF are evaluated and if the condition is true, without adjustment, the 'false' argument will be an error if txtAction2s resolves to 0 (zero) because division by zero isn't allowed in math
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:08
Joined
May 7, 2009
Messages
19,246
you can also use Switch() function:

=Switch(nz([txtAction2s],0)=0, Null, nz([txtAction1s],0)=0, Null, True, [txtAction1s]/[txtAction2s])
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 21:08
Joined
Feb 28, 2001
Messages
27,243
If you expect a possible "divide by zero" then your correct action would be

IIF ( Divisor = 0, some-constant-number, dividend/divisor )

I.e. do not trap the error. Prevent it if you know what kind of error you could expect.
 

Micron

AWF VIP
Local time
Yesterday, 22:08
Joined
Oct 20, 2018
Messages
3,478
I don't see the right parenthesis on the OP's most recent post at all..
That's not a post by the OP. I thought you were commenting on what CJ_London wrote and what was accepted as the solution. Ciao!
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 19:08
Joined
Aug 30, 2003
Messages
36,129
Note this was a 5 year old thread revived with post 13 earlier today, which caused confusion.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:08
Joined
May 7, 2009
Messages
19,246
a udf is also possible:

=IfError("$1/$2", [txtAction1s], [txtAction2s])
Code:
Public Function IfError(ByVal strExpr As String, ParamArray p() As Variant) As Variant
    ' strExpression in the form of:
    ' $1 * $2 / $3
    '
    ' we then replace each $X with the supplied parameter
    '
    Dim i As Integer, e As String
    On Error Resume Next
    For i = 0 To UBound(p)
        Select Case VarType(p(i))
        Case vbDate
            e = "#" & Format(p(i), "mm\/dd\/yyyy") & "#"
        Case vbInteger, vbSingle, vbDouble, vbLong, vbByte, vbCurrency
            e = p(i)
        Case vbString
            e = "'" & Replace(p(i), "'", "''") & "'"
        Case vbNull
            e = "Null"
        End Select
        strExpr = Replace(strExpr, "$" & i + 1, e)
    Next
    IfError = Eval(strExpr)
    If Err.Number <> 0 Then
        IfError = Null
    End If
    Err.Clear
End Function
 

Isaac

Lifelong Learner
Local time
Yesterday, 19:08
Joined
Mar 14, 2017
Messages
8,792
That's not a post by the OP. I thought you were commenting on what CJ_London wrote and what was accepted as the solution. Ciao!
oh no I was commenting on what the most recent person who revived the thread had suggested for themselves. Sorry for the confusion
 

Micron

AWF VIP
Local time
Yesterday, 22:08
Joined
Oct 20, 2018
Messages
3,478
Note this was a 5 year old thread revived with post 13 earlier today, which caused confusion.
I often catch that, but not when there's 5 or 6 posts before me. :eek:
 

Users who are viewing this thread

Top Bottom