View Full Version : Function Problem in a query


jancliff
05-11-2005, 12:30 PM
I was wondering if anyone can point me in the right direction please.
I have created a new module in my Access database (in the module object view) and I can see it in the module view. I am also able to call it in the expression builder under Functions.

Unfortuantaly if I create a query I am unable to use it. If I create it for the first time and open the query and use it, it works lovely. But if I exit my database and go back in, it does not work. I can still view it in the modules and it is still in the expression builder under functions.

My function is as follows;
Public Function GetLabourCost(WorkCodeID, PayRate, Hours) As Currency
Select Case WorkCodeID
Case "7800"
GetLabourCost = [PayRate] * 2 * [Hours]
Case "7500"
GetLabourCost = [PayRate] * 1.5 * [Hours]
Case "1000"
GetLabourCost = [PayRate] * [Hours]
Case "2000"
GetLabourCost = [PayRate] * [Hours]
Case "7000"
GetLabourCost = [PayRate] * [Hours]
Case "8000"
GetLabourCost = [PayRate] * [Hours]
Case "9000"
GetLabourCost = [PayRate] * [Hours]
Case "9500"
GetLabourCost = [PayRate] * [Hours]
Case "9999"
GetLabourCost = [PayRate] * 0 * [Hours]
Case "9550"
GetLabourCost = ([PayRate] * [Hours]) / 2
Case "9560"
GetLabourCost = [PayRate] * 0 * [Hours]
Case Else
GetLabourCost = 0
End Select
End Function


In my query I have called it as;
Expr1: GetLabourCost([WorkCodeID],[PayRate],[Hours])

I would be grateful of any advice.
Thanks

Mile-O
05-11-2005, 02:54 PM
Public Function GetLabourCost(ByVal WorkCodeID As Long, ByVal PayRate As Single, _
ByVal Hours As Long) As Currency

Select Case WorkCodeID
Case Is = 7800
GetLabourCost = PayRate * 2 * Hours
Case Is = 7500
GetLabourCost = PayRate * 1.5 * Hours
Case Is = 1000, 2000, 7000, 8000, 9000, 9500
GetLabourCost = PayRate * Hours
Case Is = 9550
GetLabourCost = (PayRate * Hours) / 2
Case Else
GetLabourCost = 0
End Select
End Function


I removed a number of these as PayRate * 0 * Hours will result in 0 anyway.

I had to guess the data type you are passing in to the function (Long, Single, Long respectively).