I'm sure I screwed this up because it's not loading to my query yet. I followed what you typed up and made some changes to meet all my requirements. In the query I created this expression: Expr: WiTaxCalc([tblEmployees].[Marital Status],[tblEmployees].[Basic Salary]) And ([tblpayrolltaxes].[Lower]) Please let me know if you need anymore information.There are various things that could and maybe should be improved about this function, but I'm just doing it fairly quickly to give you the general idea of how to turn something into a VBA function and then use it in a query.
The name should probably be changed. Local variables inside the function should probably be declared and set to the cdbl() version once and for all near the beginning instead of constantly converted throughout. I used Variant in case Nulls come in, although per your message they shouldn't be able to.
You use this in a query like: Expr2: ReturnData([tblEmployees].[Marital Status],[Basic Salary],[Lower],[Exemption credit])
Code:Function ReturnData(lngMaritalStatus As Variant, dblBasicSalary As Variant, dblLower As Variant, dblExemptionCredit As Variant) As Double If Len("" & lngMaritalStatus) = 0 Or Len("" & dblBasicSalary) = 0 Or Len("" & dblLower) = 0 Or Len("" & dblExemptionCredit) = 0 Then ReturnData = 0 Exit Function End If If (lngMaritalStatus = "1" And CDbl(dblBasicSalary) > 25727) Then ReturnData = CDbl(dblBasicSalary) - ((CDbl(dblBasicSalary) - CDbl(dblLower)) * 0.2) - CDbl(dblExemptionCredit) ElseIf (lngMaritalStatus = "2" And CDbl(dblBasicSalary) > 17780) Then ReturnData = CDbl(dblBasicSalary) - ((CDbl(dblBasicSalary) - CDbl(dblLower)) * 0.12) - CDbl(dblExem [QUOTE="Isaac, post: 1961313, member: 143967"] There are various things that could and maybe should be improved about this function, but I'm just doing it fairly quickly to give you the general idea of how to turn something into a VBA function and then use it in a query. The name should probably be changed. Local variables inside the function should probably be declared and set to the cdbl() version once and for all near the beginning instead of constantly converted throughout. I used Variant in case Nulls come in, although per your message they shouldn't be able to. You use this in a query like: Expr2: ReturnData([tblEmployees].[Marital Status],[Basic Salary],[Lower],[Exemption credit]) [CODE]Function ReturnData(lngMaritalStatus As Variant, dblBasicSalary As Variant, dblLower As Variant, dblExemptionCredit As Variant) As Double If Len("" & lngMaritalStatus) = 0 Or Len("" & dblBasicSalary) = 0 Or Len("" & dblLower) = 0 Or Len("" & dblExemptionCredit) = 0 Then ReturnData = 0 Exit Function End If If (lngMaritalStatus = "1" And CDbl(dblBasicSalary) > 25727) Then ReturnData = CDbl(dblBasicSalary) - ((CDbl(dblBasicSalary) - CDbl(dblLower)) * 0.2) - CDbl(dblExemptionCredit) ElseIf (lngMaritalStatus = "2" And CDbl(dblBasicSalary) > 17780) Then ReturnData = CDbl(dblBasicSalary) - ((CDbl(dblBasicSalary) - CDbl(dblLower)) * 0.12) - CDbl(dblExemptionCredit) Else 'all other cases ReturnData = 0 ' End If End Function
[/QUOTE]
ptionCredit)Code:Public Function WiTaxCalc(intMarStatus As Integer, dblBasSal As Double, dblAmtColA As Double, _ dblExCred As Double) As Double 'WiTaxCalc: IIf([Marital Status]=1 And [Basic Salary]<25727, [Basic Salary]-[Amount from Column A]-([Exemption credit]), IIf([Marital Status]=2 And [Basic Salary]<17780, [Basic Salary] -([Amount from Column A] - [Lower]) - ([Exemption credit]), IIf([Marital Status]=1 And [Basic Salary]>25727, [Basic Salary] -([Amount from Column A] - ([Basic Salary] - [Lower]) * 0.2)) - ([Exemption credit]), IIf([Marital Status]=2 And [Basic Salary]>17780, [Basic Salary]-([Amount from Column A]-([Basic Salary]-[Lower])*0.12))-([Exemption credit]), Dim lngBasSalHigh As Long, lngBasSalMed As Long lngBasSalHigh = 25727 lngBasSalMed = 17780 Select Case intMarStatus Case 1 'Married If dblBasSal < lngBasSalHigh Then WiTaxCalc = dblBasSal - dblAmtColA - dblExCred End If Case 2 'Single If dblBasSal < lngBasSalMed Then WiTaxCalc = dblBasSal - dblAmtColA - dblExCred End If Case Else 0 End Select End Function
Else 'all other cases
ReturnData = 0 '
End If
End Function[/CODE]