How to: Plan tasks with dependencies
Keep the tasks in a Gantt chart in the right order: link tasks, either let dependent tasks follow a change or just report what's broken, and count durations in working time.
Requires WKL Forms Object Library 1.23 or later.
Solution overview
Dependencies come from a table (DependencySource with PredecessorField, SuccessorField,
LinkTypeField, and LagField) or from a text field of the successor (PredecessorsField).
ScheduleMode determines what a change does: wgsManual doesn't move anything and lists broken
dependencies in Violations, while wgsAutomatic moves the dependent tasks. Working time comes from
WorkDays, WorkHours, and the nonworking days in HolidaySource; DurationUnit counts in days or
hours. Users link and unlink tasks with Ctrl+F2 and Ctrl+Shift+F2, from the shortcut menu, or by
dragging from the end of one bar to another.
Implementation
With Me!Gantt1.Object
' Dependencies as text in the task record instead of a table: "3FS+2;5SS"
' (FS finish-to-start, SS start-to-start, FF finish-to-finish, SF start-to-finish; lag in DurationUnit).
.DependencySource = ""
.PredecessorsField = "Predecessors"
' Calendar: Monday to Saturday, 7:00-12:00 and 12:30-16:00, nonworking days from a table.
.WorkDays = 2 + 4 + 8 + 16 + 32 + 64 ' bit 1 = Sunday ... bit 64 = Saturday
.WorkHours = "07:00-12:00;12:30-16:00"
.HolidaySource = "tblHolidays": .HolidayField = "Day"
' Automatic scheduling: link 3 -> 4 with one working day lag; 4 and its successors follow.
.ScheduleMode = wgsAutomatic
.LinkTasks 3, 4, wglFinishToStart, 1
.SetTaskDates 3, #10/8/2026#, #10/12/2026# ' 4 moves again
' Manual: nothing moves; broken dependencies are listed and drawn red.
.ScheduleMode = wgsManual
Dim item As Variant
For Each item In .Violations
Debug.Print item
Next
.Reschedule ' "Reschedule project": everything as early as allowed
Debug.Print .TaskDuration(3), .TaskSlack(3), .IsCritical(3)
End With
Remarks
- A finish is a task's last working day (with
DurationUnit= hours, the moment work ends). A task that spans a nonworking day has one working day less; the finish stays where the data puts it. - Automatic scheduling never moves tasks that have no dependencies or constraints, so the first
Rescheduledoesn't reshuffle a schedule that was typed in by hand. - In automatic mode, a task moved by hand gets a “Start No Earlier Than” constraint; map
ConstraintTypeFieldandConstraintDateFieldto keep it across sessions. LinkTasksrejects a dependency that would create a cycle (wkeCycle) and one between a task and its own summary task (wkeInvalidValue); nothing is written in that case.- The outline is part of the schedule:
IndentTaskandOutdentTask(Alt+Shift+Right/Left, or Indent/Outdent on the shortcut menu) make a task a subtask of the task above it or move it out of its summary task;TaskResourcesand Assign resources … assign resources. - Changes made in code don't raise events. The same changes made by the user raise
BeforeTaskChange,BeforeLinkAdd, orBeforeLinkDelete, where VBA can adjust or cancel them.