I'm working in Access 2000. I have a form with a series of date fields, showing the progress of a project from start to completion. There's a set of fields/controls for projected dates (when the project is projected to enter each stage of the process) and another set for actual dates. For my purposes, I'm only working with the projected dates.
There is a formula, based on the size of the project (how many hours it will take), for how many days each step of the process will require. I'm trying to set up the code so that when the projected completion date is entered, and based on the number of hours that has been entered, all the other projected dates will fill in automatically.
So in other words, if someone enters a project that will take 525 hours with a projected completion date (CompletionPJ) of 6/25/09, the database will automatically fill in the projected start date as [CompletionPJ] - 60 (and will fill in all the other projected dates in the middle according to their respective equations).
I've figured out the easy part of this (code is below), but I'm trying to figure out how to get it to count only work days. For instance, in the formula above, it would be [CompletionPJ] - [60 work days, not counting weekends or holidays].
I have a separate calendar table with CalendarID (autonumber), CalendarDate, CalendarDate2, isWorkDay, and isHoliday. (CalendarDate and CalendarDate2 are identical date fields; they make it possible for me to find the number of working days between two dates for other reports in the database.) isWorkDay and isHoliday are yes/no (all weekend dates are false in isWorkDay; weekday holidays are marked true in isHoliday). So I'm trying to figure out how to tell Access to subtract from [completionPJ] a certain number of days where isWorkDay = True and isHoliday = False.
At this point I don't have the Calendar table included in the query for this form, but I'm guessing I'll need to add it (unless it's possible to make VB code check info in a table that's not part of the data source for the form??).
Here's the code I have so far:
Expand|Select|Wrap|Line Numbers
- Private Sub txtCompletionPJ_AfterUpdate()
- If Not IsNull(Me![txtHours]) Then
- Select Case txtHours
- Case 1 To 499
- Me!txtStartPJ.Value = Me!txtCompletionPJ - 30
- Case 500 To 999
- Me!txtStartPJ.Value = Me!txtCompletionPJ - 60
- Case 1000 To 1499
- Me!txtStartPJ.Value = Me!txtCompletionPJ - 90
- Case 1500 To 1999
- Me!txtStartPJ.Value = Me!txtCompletionPJ - 120
- Case Is >= 2000
- Me!txtStartPJ.Value = Me!txtCompletionPJ - 180
- End Select
- End If
- End Sub
Anybody have an idea to help me out?
Thanks,
Angi