If I set up a task table with an Date_assigned and a number of days to complete the task I calculate the end_date field by using the code below I found in this forum
How ever when I enter the Date_assigned and update the record, nothing happens until I manually enter a value in the DaysToComplete field. I want to keep DaysToComplete Constant (5 Days) so I tried to set the attribute in the table with 5 as the default but this does not work. Is there any way I can get the form to calculate the end date without having to enter the DaysToComplete value manually in the form? Thank you very much for your help
How ever when I enter the Date_assigned and update the record, nothing happens until I manually enter a value in the DaysToComplete field. I want to keep DaysToComplete Constant (5 Days) so I tried to set the attribute in the table with 5 as the default but this does not work. Is there any way I can get the form to calculate the end date without having to enter the DaysToComplete value manually in the form? Thank you very much for your help
Code:
Public Function CountDays(startDate As Date, NoOfDays As Integer) As Integer ' Function to count no of working days Dim tmpNo As Integer Dim tmpDate As Date Dim i As Integer tmpNo = NoOfDays tmpDate = startDate i = 0 Do Until i = NoOfDays If Weekday(tmpDate) = 1 Or Weekday(tmpDate) = 7 Then tmpNo = tmpNo + 1 Else i = i + 1 End If tmpDate = tmpDate + 1 Loop CountDays = tmpNo End Function
Code:
Private Sub StartDate_AfterUpdate() If Not IsNull(Me.NoOfDays) Then Me.EndDate = Me.StartDate + CountDays(Me.StartDate, Me.NoOfDays) End If End Sub
Code:
Private Sub NoOfDays_AfterUpdate() If Not IsNull(Me.StartDate) Then Me.EndDate = Me.StartDate + CountDays(Me.StartDate, Me.NoOfDays) End If End Sub
Comment