John,
Sorry I missed this question on the last post. This would not involve
adding a new record. It would only involve updating a date field on an
existing record. I have included the full code below. In essence, the user
updates a date in a subform, after he does this, the code reschedules every
task after it based on the updated date. In runs down the subform
rescheduling dates avoiding weekends and holidays. It is very similar to the
"Workday" function in Excel.
Private Sub EndDate_AfterUpdate()
'Read in values of current record
'If altering a complete date on a complete item, do not update the rest of
schedule
If Complete.Value = -1 Then
'End Subroutine
GoTo 15
End If
x = 1 'Loop Variable
'Routine to ensure current record is selected
If Recordset.BOF = False Then
Recordset.MovePrevious
End If
If Recordset.BOF = True Then
MsgBox "No record selected. Please highlight a line in the schedule and
re-enter date", vbOKOnly
GoTo 10 ' End Program - I still have not figure out how you can update a
date and not have a current record
Else
Recordset.MoveNext
End If
BMK = Recordset.Bookmark ' set a bookmark at current record so you can return
'Read in all values for the record
pTask(x) = Task.Value
pEndDay(x) = EndDay.Value
pEndDate(x) = EndDate.Value
pLink(x) = Link.Value
pComplete(x) = Complete.Value
'If date changed is not linked then quit subroutine
If pLink(x) = 0 Or pComplete(x) = -1 Then
GoTo 10 ' task is either not linked or already complete so skip over
this record
End If
Recordset.MoveNext ' move to next record
x = x + 1
'Work day schedule routine which schedules dates ignoring weekends and
holidays
Do While Recordset.EOF = False 'Continue down schedule until End of File is
Reached
pLink(x) = Link.Value
pComplete(x) = Complete.Value
If pLink(x) = -1 And pComplete(x) = 0 Then
'Read in values for this record
pTask(x) = Task.Value
pEndDay(x) = EndDay.Value
TestDate = pEndDate(x - 1) ' Date
EndDayDiff = pEndDay(x) - pEndDay(x - 1)
If EndDayDiff >= 0 Then
StartDay = 1
StepDay = 1
Else
StartDay = -1
StepDay = -1
End If
'TEST FOR HOLIDAYS & WEEKENDS
For y = StartDay To EndDayDiff Step StepDay ' For each day that we
have to add, we must check if it is a weekend or a holiday
TestDate = TestDate + StepDay ' check the first day
5 If Weekday(TestDate) = 7 Or Weekday(TestDate) = 1 Then
'Saturday or Sunday
TestDate = TestDate + StepDay
End If
If Weekday(TestDate) = 1 Or Weekday(TestDate) = 7 Then 'Sunday
or Saturday
TestDate = TestDate + StepDay
End If
'Check for Holiday
Dim TestDateEqualsHoliday As Variant
TestDateEqualsHoliday = DLookup(TestDate, "[Holidays]",
"[HolidayDate]= #" & TestDate & "#")
If Not IsNull(TestDateEqualsHoliday) Then
' A date exists on the holiday table. I had Dlookup return the
'HolidayID, that way you can exactly know exactly what date
conflicts,
'and if you wanted, use that to display to the end user
'If found loop back up and verify that new date is not a
weekend or a consecutive holiday
TestDate = TestDate + StepDay
GoTo 5 ' This date is either a holiday or a weekend so move
skip to next date and check it
' Else the date doesn't exist.
End If
Next y
'Change date value based on updated dates
pEndDate(x) = TestDate
EndDate.Value = pEndDate(x)
x = x + 1
Recordset.MoveNext
Else
'If record is not linked don't read in, move to next
Recordset.MoveNext
End If
Loop
10 'Goto for return to bmk and end subroutine
Recordset.Bookmark = BMK
15 ' Goto for end subroutine
End Sub
John Spencer said:
If the record is a new record and (by definition) not saved then I believe
you don't have a current record and you don't have a bookmark in the
recordset for the not-yet-existinig record. Is that the case here?
I can't tell from the snippets of code you have posted what is happening.