IFERROR function equivalent in Access

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
 
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:
Oops, didn't see there was a page 2.
 
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
 
you can also use Switch() function:

=Switch(nz([txtAction2s],0)=0, Null, nz([txtAction1s],0)=0, Null, True, [txtAction1s]/[txtAction2s])
 
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.
 
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!
 
Note this was a 5 year old thread revived with post 13 earlier today, which caused confusion.
 
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
 
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
 
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

Back
Top Bottom