Delphi Code - Get Microsoft Outlook Tasks within a Date Range
Here is a simple Delphi procedure that programmatically retrieves all Microsoft Outlook tasks that are due within a date range. The code uses the task DueDate property. Note that the DueDate property is timeless (i.e., date is preserved but the time component is set to zero). The code works well whether or not Outlook is already open. However, please note that the code will not work if Outlook is closed, and your installed Outlook requires any form of authentication upon launching the program. The most relevant parts of the code are highlighted. Comments are included to explain the code. If you copy and paste the code into your program, be sure to change the form and procedure names to match your setup. For additional Outlook automation solutions, see Microsoft Outlook Automation with Delphi.
— share —
procedure TForm1.GetMicrosoftOutlookTasksWithinADateRange(Sender: TObject); var Count: Integer; StartDate, EndDate: TDate; StartDateString, EndDateString, OutlookFindString: String; OutlookApplication, OutlookNameSpace, OutlookFolder, OutlookFolderTaskItems, OutlookTaskItem: Variant; begin //be sure ComObj and Variants units are included in the "uses" clause
Count := 0;
StartDate := StrToDate('9/1/2022'); //start of date window EndDate := StrToDate('9/30/2022'); //end date for search window //note: the above date range is used to search for DueDate within this range //note: DueDate does not have a time component