Microsoft Office Tutorials and References
In Depth Information
Creating Task Items Automatically in Outlook
'Refer to Form_Delete event to see how it is being set¶
'Variable declaration¶
Dim DelTaskID As String¶
' * * * * *¶
Private Sub AddOLTask()¶
'Outlook Application Objects declaration¶
Dim olApp As Object 'Outlook.Application¶
Dim olNS As Object 'Outlook.NameSpace¶
Dim olTask As Object 'Outlook.TaskItem¶
Dim varShipDate As Date¶
'Validate if current date field value and saved OLTaskItemID¶
'for this record¶
'If both value are invalid then cannot add/edit a Task Item¶
If Not IsDate(Me.ShipDate) And IsNull(Me!OLTaskItemID) _¶
Then Exit Sub¶
'Continue if an error occurs¶
On Error Resume Next¶
Set olApp = GetObject(, "Outlook.Application")¶
'Error occurs if Outlook Application is not running¶
If Err Then¶
'If error then launch Outlook Application¶
Set olApp = CreateObject("Outlook.Application")¶
End If¶
'Create Name Space by using MAPI data source¶
'for current Outlook session to manage objects¶
Set olNS = olApp.GetNamespace("MAPI")¶
'Validate OLTaskItemID field value for current record¶
If IsNull(Me!OLTaskItemID) Then¶
'There is not a saved Task Item for this record¶
'Create new Task Item object¶
''olTaskItem = 3¶
Set olTask = olApp.CreateItem(3)¶
ElseIf Not Trim(Me!OLTaskItemID) = "" Then¶
'There is a saved Task Item for this record¶
'Get it to modify by using modified record¶
Set olTask = olNS.GetItemFromID(Me!OLTaskItemID)¶
'Make sure if Task Item is succesfully retrieved¶
'Otherwise create new Task Iteim¶
If olTask Is Nothing Then¶
Set olTask = olApp.CreateItem(3)¶
'Validate existing Task Item's current parent folder¶
If olTask.Parent.Class = 2 Then¶
'If Task Item was deleted then code will still find it¶
'by using EntryID (OLTaskItemID)¶
'Validate if it was deleted and move into Tasks folder¶
'in case it was¶
'Validation is being done by matching Deleted Items¶
'and Task Item's parent folder names¶
'olFolderDeletedItems = 3¶
Search JabSto ::

Custom Search