Hi there.
I have written some code that takes date fields and tries to create an outlook task out of them. It works fine when you initially run the code, but if a task already exists and you just want to update it, the DeleteOutlookTask method is failing with an error:
Error -2147221233 The operation failed.
The error is happening on the line
"Set objItem = objNS.GetItemFromID(strEntryID)"
I've double checked the outlookentryid to ensure that what I save in the database when the task is created is exactly the same value that I pass to this routine.
Any help would be appreciated.
Public Sub DeleteOutlookTask(strEntryID As String)
On Error GoTo DeleteOutlookTask_Err
Dim objOL, objNS, objItem
Set objOL = CreateObject("Outlook.Application")
Set objNS = objOL.GetNamespace("MAPI")
Debug.Print "delete outlook: " & strEntryID
Set objItem = objNS.GetItemFromID(strEntryID)
If Not objItem Is Nothing Then
objItem.Delete
Else
MsgBox ("Original item not found")
End If
Exit Sub
DeleteOutlookTask_Err:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description
End Sub
I have written some code that takes date fields and tries to create an outlook task out of them. It works fine when you initially run the code, but if a task already exists and you just want to update it, the DeleteOutlookTask method is failing with an error:
Error -2147221233 The operation failed.
The error is happening on the line
"Set objItem = objNS.GetItemFromID(strEntryID)"
I've double checked the outlookentryid to ensure that what I save in the database when the task is created is exactly the same value that I pass to this routine.
Any help would be appreciated.
Public Sub DeleteOutlookTask(strEntryID As String)
On Error GoTo DeleteOutlookTask_Err
Dim objOL, objNS, objItem
Set objOL = CreateObject("Outlook.Application")
Set objNS = objOL.GetNamespace("MAPI")
Debug.Print "delete outlook: " & strEntryID
Set objItem = objNS.GetItemFromID(strEntryID)
If Not objItem Is Nothing Then
objItem.Delete
Else
MsgBox ("Original item not found")
End If
Exit Sub
DeleteOutlookTask_Err:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description
End Sub