I am trying to create new task by clicking on Userform button with the following code:
Private Sub CreateTaskCMD_Click()
Dim oTask As TaskItem
Dim SelFolder As Outlook.Folder
Set oTask = Outlook.CreateItem(olTaskItem)
Set SelFolder = ObjNS.Folders(1).Folders(TaskFoldersList.List(TaskFoldersList.ListIndex, 1))
With oTask
'include time and from in subject of task
'.Subject = ""
'.Body = ""
.StartDate = Date
.Save
.Move SelFolder
.Save
.Display
End With
Set SelFolder = Nothing
Set oTask = Nothing
End Sub
The code gets the folder number from a list which already updated.
new task is created and moved to the selected folder, but problem is when I see the task window I cannot rename, or make changes in that rather I have to close it and then reopen it.
I am receiving message "The item cannot be saved because it was modified by another user or in another window"
I have already release the oTask
at the end of subroutine? don't know where I am holding that new task. or where I need to release it from?
CodePudding user response:
Instead of creating in the default folder then moving, you can add to the non-default task folder.
Option Explicit
Private Sub CreateTaskCMD_Click()
Dim oTask As TaskItem
Dim SelFolder As folder
Set SelFolder = objNS.Folders(1).Folders(TaskFoldersList.list(TaskFoldersList.ListIndex, 1))
Set oTask = SelFolder.items.Add(olTaskItem)
With oTask
.StartDate = Date
.Display
End With
Set SelFolder = Nothing
Set oTask = Nothing
End Sub