Pay Categories

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

I have a sub form setup to calculate a workers pay.
Depending on what job he is doing, he could be payed by
the pieces he produces, by the hours he works or by his
average hourly wage. I thought that this code would work,
but it didn't. Can some one point me in the right
direction please?

Private Sub Pay_AfterUpdate()
Dim PieceRate As Integer
Dim HourlyRate As Integer
Dim AverageRate As Integer

PieceRate = [COMPANY_NO] >= "02" And [COMPANY_NO] <= "79"
HourlyRate = [COMPANY_NO] >= "C1" And [COMPANY_NO] <= "M9"
AverageRate = [COMPANY_NO] = "01"

If [COMPANY_NO] = PieceRate Then
[Pay] = [Pieces] * [Rate]

If [COMPANY_NO] = HourlyRate Then
[Pay] = [WageBase] * [Hours]

If [COMPANY_NO] = AverageRate Then
[Pay] = [AverageWage] * [Hours]

End If

End Sub
 
Hi Mike

I think where you are going wrong is that you are setting your PieceRate,
HourlyRate, and AverageRate variables to Boolean values (true or false),
rather than integers. This means that your If ... Then statements won't work
as they are.

However, you should be able to get this to work by making two simple
changes:

1. Declare your variables as Boolean, not integer
2. Change your If ... Then statements so that they look like

If PieceRate Then

etc.

HTH

Adam
 
OK, try this. Don't bother with any of your PieceRate variables. Instead, in
the Select Case statements, try writing your statements with [Pay] =
[Pieces] * [Rate].

If that doesn't work, it may be because you can't refer to fields in this
way. Perhaps you can: I'm not sure.

A way that you can refer to fields in a form that I know works is to use the
syntax Me.FieldName.

HTH

Adam
 
Back
Top