I'm using a public function to calculate the difference between to numbers in %.
To make sure I don't get a "Division by Zero" error I'm using a switch.
The numbers come from a table where the datatype is Currency.
The function works - but still it returns #Error on my report when there is no data in the fields...
Public Function DiffPct(Switch As Integer, Numero1, Numero2 As Double) As Double
Dim VARWork As Double
If IsNull(Switch) Then
DiffPct = 0
Else
VARWork = ((Numero1 / Numero2) - 100)
DiffPct = 100 * (Abs(VARWork) - Fix(Abs(VARWork)))
End If
End Function
I'm calling the function from a SQL where the return value is stored in a variable (Benefit), which I'm using as datasource on my report.
"SELECT comunidad.Comunidad_Autonomia, [Codigo Postal].texto, " & _
"Sum(TempTabla1.NrDeLibros) AS SumDeLibros, Sum(TempTabla1.FactSin) AS FactSinIVA, " & _
"Sum(TempTabla1.FactCon) AS FactNeta, ([FactNeta]*166.386) AS FactNetaPtas, " & _
"DiffPct([SumDeLibros], [FactNeta], [FactSinIVA]) AS Benefit " & _
"FROM TempTabla1 RIGHT JOIN ([Codigo Postal] "
Can anyone tell why?
Thanks in advance
Søren
To make sure I don't get a "Division by Zero" error I'm using a switch.
The numbers come from a table where the datatype is Currency.
The function works - but still it returns #Error on my report when there is no data in the fields...

Public Function DiffPct(Switch As Integer, Numero1, Numero2 As Double) As Double
Dim VARWork As Double
If IsNull(Switch) Then
DiffPct = 0
Else
VARWork = ((Numero1 / Numero2) - 100)
DiffPct = 100 * (Abs(VARWork) - Fix(Abs(VARWork)))
End If
End Function
I'm calling the function from a SQL where the return value is stored in a variable (Benefit), which I'm using as datasource on my report.
"SELECT comunidad.Comunidad_Autonomia, [Codigo Postal].texto, " & _
"Sum(TempTabla1.NrDeLibros) AS SumDeLibros, Sum(TempTabla1.FactSin) AS FactSinIVA, " & _
"Sum(TempTabla1.FactCon) AS FactNeta, ([FactNeta]*166.386) AS FactNetaPtas, " & _
"DiffPct([SumDeLibros], [FactNeta], [FactSinIVA]) AS Benefit " & _
"FROM TempTabla1 RIGHT JOIN ([Codigo Postal] "
Can anyone tell why?
Thanks in advance
Søren