I have a select query, that works with a function and I don't understand why I am getting the results I am. This is a section of the query that has the problem:
IIf([JuryVacCount]>2,(GetNumWeeks()+1))
FROM tblEmployees AS Emp LEFT JOIN tblAttendance AS Att
ON Emp.EmployeeNumber=Att.EmployeeNumber
WHERE (Emp.EmpStatusType="Active"
And Emp.PayType="per Hour"
And (Att.DateWeekStarting Between Nz([Enter Start Date],DateAdd("ww",-1-GetNumWeeks(),Date()))
And Dateadd("ww",GetNumWeeks(),Nz([Enter Start Date],
DateAdd("ww",-1-GetNumWeeks(),Date()))))
This is the function:
Function GetNumWeeks(Optional num As Integer)
If num = 0 Then
GetNumWeeks = 13
Else
GetNumWeeks = num
End If
End Function
What it is supposed to do is increase the Function variable from 13 to 14. What it is doing is at the end of the row, where JuryVacCount>2, it put a 14 in a new column. Could someone please tell me what is wrong with my query and/or function? Also how to reset the GetNumWeeks() by to the default when a new employee number comes along. I am ready to pull my hair out with this one. I am inches away from finishing this database and this is the only thing holding me back, so thank you very much in advance to anyone who comes up with the answer.
IIf([JuryVacCount]>2,(GetNumWeeks()+1))
FROM tblEmployees AS Emp LEFT JOIN tblAttendance AS Att
ON Emp.EmployeeNumber=Att.EmployeeNumber
WHERE (Emp.EmpStatusType="Active"
And Emp.PayType="per Hour"
And (Att.DateWeekStarting Between Nz([Enter Start Date],DateAdd("ww",-1-GetNumWeeks(),Date()))
And Dateadd("ww",GetNumWeeks(),Nz([Enter Start Date],
DateAdd("ww",-1-GetNumWeeks(),Date()))))
This is the function:
Function GetNumWeeks(Optional num As Integer)
If num = 0 Then
GetNumWeeks = 13
Else
GetNumWeeks = num
End If
End Function
What it is supposed to do is increase the Function variable from 13 to 14. What it is doing is at the end of the row, where JuryVacCount>2, it put a 14 in a new column. Could someone please tell me what is wrong with my query and/or function? Also how to reset the GetNumWeeks() by to the default when a new employee number comes along. I am ready to pull my hair out with this one. I am inches away from finishing this database and this is the only thing holding me back, so thank you very much in advance to anyone who comes up with the answer.