obusweetpea
New member
- Local time
- Today, 04:42
- Joined
- Jan 8, 2018
- Messages
- 3
Good afternoon, all! I am very new to Access, and even newer to VBA. I recently designed a database for work, and I'm trying to create a new query. For my new query, I have a "DateReturned" field in an existing table, and I want to run all records, adding 10 working days to the "DateReturned" to display the "ExpectedBy" date. Can someone please advise the easiest way to do this? I do already have a module which calculates working days (excluding holidays) between two dates, but I can't seem to get it to work in the new query. The code for that module is below.
TIA for any and all assistance. Also, as a beginner, elementary terminology is appreciated whenever possible. Thanks!
Public Function Workdays(ByRef startDate As Date, _
ByRef EndDate As Date, _
Optional ByRef strHolidays As String = "Holidays" _
) As Integer
' Returns the number of workdays between startDate
' and endDate inclusive. Workdays excludes weekends and
' holidays. Optionally, pass this function the name of a table
' or query as the third argument. If you don't the default
' is "Holidays".
On Error GoTo Workdays_Error
Dim nWeekdays As Integer
Dim nHolidays As Integer
Dim strWhere As String
' DateValue returns the date part only.
startDate = DateValue(startDate)
EndDate = DateValue(EndDate)
nWeekdays = Weekdays(startDate, EndDate)
If nWeekdays = -1 Then
Workdays = -1
GoTo Workdays_Exit
End If
TIA for any and all assistance. Also, as a beginner, elementary terminology is appreciated whenever possible. Thanks!
Public Function Workdays(ByRef startDate As Date, _
ByRef EndDate As Date, _
Optional ByRef strHolidays As String = "Holidays" _
) As Integer
' Returns the number of workdays between startDate
' and endDate inclusive. Workdays excludes weekends and
' holidays. Optionally, pass this function the name of a table
' or query as the third argument. If you don't the default
' is "Holidays".
On Error GoTo Workdays_Error
Dim nWeekdays As Integer
Dim nHolidays As Integer
Dim strWhere As String
' DateValue returns the date part only.
startDate = DateValue(startDate)
EndDate = DateValue(EndDate)
nWeekdays = Weekdays(startDate, EndDate)
If nWeekdays = -1 Then
Workdays = -1
GoTo Workdays_Exit
End If