I am totoally new to Access VBA. I have a database that has a query which calculates the number between two dates can output this information to a report when requested. However, I want to calculate the number for working days instead so that it doesnt include weekends. I found some code:
Public Function GetNumberOfWorkDays(sStartDate, sEndDate)
Dim iDays
Dim iWorkDays
Dim sDay
Dim i
iDays = DateDiff("d", sStartDate, sEndDate)
iWorkDays = 0
For i = 0 To iDays
'First day of the week is sunday
sDay = WeekDay(DateAdd("d", i, sStartDate))
If sDay <> 1 And sDay <> 7 Then
iWorkDays = iWorkDays + 1
End If
Next
GetNumberOfWorkDays = iWorkDays
End Function
However, the problem is how do I implement this code into my database? There is no place to enter the code in the query. Do I have to replace the start date and end date names with the date field names used in my database?
Please could somebody give me some idea as I have never used Functions before? Thanks!
Public Function GetNumberOfWorkDays(sStartDate, sEndDate)
Dim iDays
Dim iWorkDays
Dim sDay
Dim i
iDays = DateDiff("d", sStartDate, sEndDate)
iWorkDays = 0
For i = 0 To iDays
'First day of the week is sunday
sDay = WeekDay(DateAdd("d", i, sStartDate))
If sDay <> 1 And sDay <> 7 Then
iWorkDays = iWorkDays + 1
End If
Next
GetNumberOfWorkDays = iWorkDays
End Function
However, the problem is how do I implement this code into my database? There is no place to enter the code in the query. Do I have to replace the start date and end date names with the date field names used in my database?
Please could somebody give me some idea as I have never used Functions before? Thanks!