Code:
Public Function CalcTax(pGross As Currency) As Currency
Dim d As DAO.Database
Dim r As DAO.Recordset
Dim sSQL As String
Dim tmpGross As Currency
Const MinWage As Currency = 2166.68 ' <= hard coded from tax table
Set d = CurrentDb
CalcTax = 0
tmpGross = Int((pGross * 100) + 0.5) / 100
If tmpGross >= MinWage Then
sSQL = "SELECT [TaxAmount] FROM IncomeTaxMonthly WHERE " & tmpGross & " Between PayRangeLow And PayRangeHigh"
Set r = d.OpenRecordset(sSQL)
If Not r.EOF Then
CalcTax = r("TaxAmount")
End If
End If
On Error Resume Next
r.Close
Set r = Nothing
Set d = Nothing
End Function
In the query, the tax column would look like this:
Code:
Taxes: CalcTax([GROSS])
This executes in about < 5 seconds for approx 1042 records.
Possible Modification:
Instead of hard coding the min wage, you could run code on startup to initalize a glogal variable, then use that instead of the constant in the code.