HELP!-I'm a newbie in Access VBA and need help in creating a new field in a query that uses a function in a module.
In this query I created a new field called TotalImpact that uses a CustomerKWH function that contains 2 arguments (called "Impact" and "InstallMonth" in the module). The value in the MonthlyImpact field (an expression) is entered as the "Impact" argument and the value in the InstallMonth is entered as the "Month" argument. The CustomerKWH function calculates based on the Month X the MonthlyImpact.
I have written the following code, but I am not able to get calculations when I run my query.
Function CustomerKWH(Impact, InstallMonth)
Dim JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC As Date
If InstallMonth = JAN Then
CustomerKWH = Impact * 12
ElseIf InstallMonth = FEB Then
CustomerKWH = Impact * 11
ElseIf InstallMonth = MAR Then
CustomerKWH = Impact * 10
ElseIf InstallMonth = APR Then
CustomerKWH = Impact * 9
ElseIf InstallMonth = MAY Then
ElseIf InstallMonth = JUN Then
CustomerKWH = Impact * 7
ElseIf InstallMonth = JUL Then
CustomerKWH = Impact * 6
ElseIf InstallMonth = AUG Then
CustomerKWH = Impact * 5
ElseIf InstallMonth = SEP Then
CustomerKWH = Impact * 4
ElseIf InstallMonth = OCT Then
CustomerKWH = Impact * 3
ElseIf InstallMonth = NOV Then
CustomerKWH = Impact * 2
ElseIf InstallMonth = DEC Then
CustomerKWH = Impact * 1
End If
End Function
Basically, I need to have this CustomerKWH function to automatically calculate the MonthlyImpact field X whatever the number, depending on the Month.
I hope this makes sense. Thanks for your help.
In this query I created a new field called TotalImpact that uses a CustomerKWH function that contains 2 arguments (called "Impact" and "InstallMonth" in the module). The value in the MonthlyImpact field (an expression) is entered as the "Impact" argument and the value in the InstallMonth is entered as the "Month" argument. The CustomerKWH function calculates based on the Month X the MonthlyImpact.
I have written the following code, but I am not able to get calculations when I run my query.
Function CustomerKWH(Impact, InstallMonth)
Dim JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC As Date
If InstallMonth = JAN Then
CustomerKWH = Impact * 12
ElseIf InstallMonth = FEB Then
CustomerKWH = Impact * 11
ElseIf InstallMonth = MAR Then
CustomerKWH = Impact * 10
ElseIf InstallMonth = APR Then
CustomerKWH = Impact * 9
ElseIf InstallMonth = MAY Then
ElseIf InstallMonth = JUN Then
CustomerKWH = Impact * 7
ElseIf InstallMonth = JUL Then
CustomerKWH = Impact * 6
ElseIf InstallMonth = AUG Then
CustomerKWH = Impact * 5
ElseIf InstallMonth = SEP Then
CustomerKWH = Impact * 4
ElseIf InstallMonth = OCT Then
CustomerKWH = Impact * 3
ElseIf InstallMonth = NOV Then
CustomerKWH = Impact * 2
ElseIf InstallMonth = DEC Then
CustomerKWH = Impact * 1
End If
End Function
Basically, I need to have this CustomerKWH function to automatically calculate the MonthlyImpact field X whatever the number, depending on the Month.
I hope this makes sense. Thanks for your help.