sjbtax
Member
- Outlook version
- Email Account
Operating system:: Windows 10
Outlook version: Outlook 365
Email type or host: Microsoft 365
Outlook version: Outlook 365
Email type or host: Microsoft 365
I am trying to add some text to a custom field I have created when a task is overdue so that I can use it when sorting some of my lists.
I plan on running it automatically somehow at the start of the day and then hoping to apply it when a new task is added or changed for new or updated appointment during the day.
I have tried the following code, however even though it does not cause any errors, it does not place anything in my custom field "TaskStatus" either. Anyone have any ideas?
I plan on running it automatically somehow at the start of the day and then hoping to apply it when a new task is added or changed for new or updated appointment during the day.
I have tried the following code, however even though it does not cause any errors, it does not place anything in my custom field "TaskStatus" either. Anyone have any ideas?
Code:
Sub UpdateTaskStatus()
Dim objTask As Outlook.TaskItem
Dim overdueDate As Date
' Define the overdue threshold (e.g., overdue if due date is in the past)
overdueDate = Date
On Error Resume Next ' Continue if an error occurs (e.g., not a task item)
' Check if the current item is a task item
If Application.ActiveInspector.CurrentItem.Class = olTask Then
Set objTask = Application.ActiveInspector.CurrentItem
' Check if the task is overdue
If objTask.DueDate < overdueDate And objTask.Complete = False Then
' Update custom field "TaskStatus" with "Overdue"
objTask.UserProperties("TaskStatus").Value = "Overdue"
objTask.Save ' Save the changes
End If
End If
Set objTask = Nothing ' Release the object reference
On Error GoTo 0 ' Reset error handling
End Sub