View Full Version : Help Creating a Function


aqif
07-15-2001, 10:07 PM
Hi All http://www.access-programmers.co.uk/ubb/smile.gif

I want to create a dynamic function which can work with any field. As an example I want to create a function calculating Tax Amount. Following calculation will be in the function

Public Function Tax_Amt()

Tax_Amt = Total_Amount - (Total_Amount * 2.5)

End Function

The problem is that every database has got different filed names. I want to create a function and then use it like

Private Sub MyField_Enter()
tax_Amt(MyField)
End Sub

And it should perform the above calculation. I want to use a function which can be used on any form with any numerical field. I dont know I m making much sense or not but this is just an example in order for me to learn. Any detailed explanation will be much appreciated.

Cheers!
Aqif

KDg
07-16-2001, 12:55 AM
Hi Aqif,

looks like you've pretty much got the answer in your question.

You'd make a function that would take a figure as a parameter. eg

Public Function Tax_Amt(dblTotalAmount as Double) as Double

Tax_Amt = dblTotalAmount - (dblTotalAmount * 2.5)

End Function


then you'd just call it from your form/query etc.

me.txtTaxPerc=Tax_Amt(VarName_OrFigure)

To call it in a query you can put something like

Tax_Amount: Tax_Amt(FieldName)
in the field row of the QBE grid

HTH

Drew

[This message has been edited by KDg (edited 07-16-2001).]

aqif
07-16-2001, 01:39 AM
Heyyy!!!! Why I m not seeing any reply.?? When it is showing Replies as 1

Aqif

aqif
07-16-2001, 01:40 AM
sorryyyy http://www.access-programmers.co.uk/ubb/smile.gif Now i see the reply