P
Peter
Hi all,
I have a public function that performs some simeple calculations but when i
call the function from another part of the code it always returns zero
despite it makes the calculations right. can somebody show me the problem?
herebelow i include the function code and the calling code:
Public Function calc_load_amnt(n As Integer, v_cov_id As Long) As Currency
Dim l_first As Currency
Dim l_each As Currency
Dim result As Currency
If IsNull(DLookup("[assl_amount]", "t_assoc_loadings", "[assladd_rule] = 1
AND [asscov_id] = " & v_cov_id)) = True Then
l_first = 0
Else
l_first = DLookup("[assl_amount]", "t_assoc_loadings", "[assladd_rule] =
1 AND [asscov_id] = " & v_cov_id)
End If
If IsNull(DLookup("[assl_amount]", "t_assoc_loadings", "[assladd_rule] = 2
AND [asscov_id] = " & v_cov_id)) = True Then
l_each = 0
Else
l_each = DLookup("[assl_amount]", "t_assoc_loadings", "[assladd_rule] =
2 AND [asscov_id] = " & v_cov_id)
End If
result = l_first + (n * l_each)
calc_load_amnt = result
l_first = Empty
l_each = Empty
result = Empty
End Function
............
'calling procedure
Private Sub install_num_AfterUpdate()
Dim variab As Currency
varaib = calc_load_amnt(Me.install_num, Me.cov_id)
MsgBox variab 'Here i get zero instead the actual result
variab = Empty
End Sub
I have a public function that performs some simeple calculations but when i
call the function from another part of the code it always returns zero
despite it makes the calculations right. can somebody show me the problem?
herebelow i include the function code and the calling code:
Public Function calc_load_amnt(n As Integer, v_cov_id As Long) As Currency
Dim l_first As Currency
Dim l_each As Currency
Dim result As Currency
If IsNull(DLookup("[assl_amount]", "t_assoc_loadings", "[assladd_rule] = 1
AND [asscov_id] = " & v_cov_id)) = True Then
l_first = 0
Else
l_first = DLookup("[assl_amount]", "t_assoc_loadings", "[assladd_rule] =
1 AND [asscov_id] = " & v_cov_id)
End If
If IsNull(DLookup("[assl_amount]", "t_assoc_loadings", "[assladd_rule] = 2
AND [asscov_id] = " & v_cov_id)) = True Then
l_each = 0
Else
l_each = DLookup("[assl_amount]", "t_assoc_loadings", "[assladd_rule] =
2 AND [asscov_id] = " & v_cov_id)
End If
result = l_first + (n * l_each)
calc_load_amnt = result
l_first = Empty
l_each = Empty
result = Empty
End Function
............
'calling procedure
Private Sub install_num_AfterUpdate()
Dim variab As Currency
varaib = calc_load_amnt(Me.install_num, Me.cov_id)
MsgBox variab 'Here i get zero instead the actual result
variab = Empty
End Sub