Error when populating query?

L

Leslie Coover

Both of the functions that follow calculate specific fields in a query.

The first function works as expected and returns zero if the TypeS is not
equal to "MF"

The second function also works as expected but instead of leaving a zero if
TypeS is not equal to "B_CORP" it leaves #Error. Can you tell me how to get
rid of the #Error? Thanks

Function DiscRateMF(Purchase_Price As Double, Pro_Cur_Val As Double, _
DD As Double, TypeS As String) As Double

Select Case TypeS
Case "MF"
If DD <= 365 Then
DiscRateMF = (Pro_Cur_Val / Purchase_Price) - 1
Else
DiscRateMF = ((Pro_Cur_Val / Purchase_Price) ^ (1 / (DD /
365))) - 1
End If
Case Else
End Select

End Function

--------------------------------

Function DiscRateB(Purchase_Price As Double, Pro_Cur_Val As Double, _
DD As Double, TypeS As String, DX As Double, Coupon As Double, M As Double)
As Double
Dim C As Double, F As Double, I As Double, PV As Double, S As Double

Select Case TypeS

Case "B_CORP"
For I = 0.001 To 2 Step 0.001
C = (Coupon * 1000) / M
S = (I / M)
F = (1 + S) ^ ((DX / 365) * M)
PV = C * ((1 - (1 / F)) / S) + 1000 / F

If Pro_Cur_Val - PV < 2 Then
DiscRateB = I
Else
End If
Next I
Case Else
End Select
 
P

Paul Overway

Is there a Null in any of the values being passed to the function? If so,
that is the cause.

If you're going to use a function in queries where the function argument may
contain Nulls, the argument needs to be declared as a Variant....and you
need to test for Null. Or you need to use the Nz function to coerce the
Null to zero before passing it to the function.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top