I have a set of code in a form that I really need to move into a function to use in other places as well. It works perfectly in the form, but when i put it into a module i get the error "you cancelled the previous operation". What it does is calculate interest based on an interest rate that fluxuates over time. I'll paste it up real quick.. but don't make fun of it
Why do I get this problem? I changed all the variable names to match is all I did. TIA!
Code:
Option Explicit
Option Compare Database
Public Function CalcInterest(grossreceipts As Currency, duedate As Date, datepaid As Date) As Currency
Dim beg_intrate As Long
Dim beg_intrate_begin As Date
Dim beg_intrate_end As Date
Dim end_intrate_begin As Date
Dim end_intrate_end As Date
Dim end_intrate As Long
Dim totalint As String
Dim checkend As Boolean
Dim begint, midint, endint As Currency
beg_intrate_begin = DLookup("[beginning date]", "[interest rates]", "[beginning date] <= duedate AND duedate <= [ending date]")
beg_intrate_end = DLookup("[ending date]", "[interest rates]", "[beginning date] <= duedate] AND duedate <= [ending date]")
beg_intrate = DLookup("[interest rate]", "[interest rates]", "[beginning date] <= duedate] AND duedate <= [ending date]")
end_intrate_begin = DLookup("[beginning date]", "[interest rates]", "[beginning date] <= datepaid AND [datepaid <= [ending date]")
end_intrate_end = DLookup("[ending date]", "[interest rates]", "[beginning date] <= datepaid AND [datepaid <= [ending date]")
end_intrate = DLookup("[interest rate]", "[interest rates]", "[beginning date] <= datepaid AND [datepaid <= [ending date]")
If datepaid <= beg_intrate_end Then begint = (DateDiff("d", duedate, datepaid) * beg_intrate)
If datepaid > beg_intrate_end Then begint = (DateDiff("d", duedate, beg_intrate_end) * beg_intrate)
checkend = IsNull(DSum("[interest rate]", "[interest rates]", "duedate < [beginning date] AND datepaid > [ending date]"))
If datepaid > beg_intrate_end Then
endint = (DateDiff("d", end_intrate_begin, datepaid) + 1) * end_intrate
If checkend = False Then midint = DSum("[total int rate]", "[interest rates]", "duedate < [beginning date] AND datepaid > [ending date]")
End If
totalint = begint + midint + endint
totalint = Round(totalint, "9")
If datepaid < duedate Then totalint = 0
CalcInterest = Round(grossreceipts * totalint, 2)
End Function