V
vonclausowitz
Hi all,
We share a mailbox and tasks with four persons. I use this code to
catch a selection in my tasks and if a task is changed the user defined
field "Updater" is changed. There are two problems with this code:
1. first of all, if someone else then me changes a task the code will
think it is me and update the field using my username;
2. secondly if I change a task and this task is completed, the field
Updater gets changed accordingly, the task is marked as Completed but
then Outlook gets like crazy and is unaccessable.
I don't know if if has something to do with the fact that the tasks
have a daily recurrence?
Option Explicit
Dim gUser As String
Public sValueRole As String
Public sValueDueDate As String
Public sValueSubject As String
Public strCurrentUser As String
Public nmsUser As Outlook.NameSpace
Public newTaskFolder As MAPIFolder
Public WithEvents oTask As Outlook.TaskItem 'definieer een taak
Public WithEvents oTasks As Outlook.Items 'definieer de taken
Public WithEvents oExplorer As Outlook.Explorer
Public WithEvents oApplication As Outlook.Application
Private Sub Application_Startup()
gUser = vbGetUserName()
Initialize_handler
End Sub
Public Sub Initialize_handler()
Dim oNS As Outlook.NameSpace
Set oNS = Application.GetNamespace("MAPI")
If gUser = "Marco" Then
Set newTaskFolder =
oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks).Folders("Taken
Oud")
Set oTasks =
oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks).Items
End If
Set oExplorer = Application.ActiveExplorer
Set oApplication = Outlook.Application
strCurrentUser = gUser
End Sub
Private Sub oExplorer_SelectionChange()
If oExplorer.CurrentFolder.Name = "Taken" Then
If strCurrentUser = "Marco" Then
If oExplorer.Selection.Count <> 0 Then
Set oTask = oExplorer.Selection(1)
sValueRole = oTask.Role
sValueDueDate = oTask.DueDate
sValueSubject = oTask.Subject
End If
End If
End If
End Sub
Private Sub oTasks_ItemChange(ByVal item As Object)
Dim Response As Integer
Dim oTask As TaskItem
Set oTask = item
If Not oTask.Role = "" And Not sValueRole = "" Then
If CDate(oTask.Role) > CDate(sValueRole) Then
oTask.UserProperties("Updater") = strCurrentUser & " " &
Format(Date, "DD-MM-YYYY")
oTask.Save
If (CDate(oTask.Role) = Date - 1 And oTask.DueDate = Date) Or
(CDate(oTask.Role) = Date And oTask.DueDate = Date) Then
'wil je de taak afvinken?
Response = MsgBox("Wil je deze taak afvinken '" &
oTask.Subject & "'?", vbYesNo, "Doorgaan")
If Response = 6 Then
oTask.Status = olTaskComplete
oTask.Save
End If
End If
End If
End If
End Sub
What I'm asking is:
1. when using these tasks with four users on different machines how can
the code tell who is updating the task?
2. why does Outlook get in a loop when I update and complete one task?
Regards
Marco
The Netherlands
We share a mailbox and tasks with four persons. I use this code to
catch a selection in my tasks and if a task is changed the user defined
field "Updater" is changed. There are two problems with this code:
1. first of all, if someone else then me changes a task the code will
think it is me and update the field using my username;
2. secondly if I change a task and this task is completed, the field
Updater gets changed accordingly, the task is marked as Completed but
then Outlook gets like crazy and is unaccessable.
I don't know if if has something to do with the fact that the tasks
have a daily recurrence?
Option Explicit
Dim gUser As String
Public sValueRole As String
Public sValueDueDate As String
Public sValueSubject As String
Public strCurrentUser As String
Public nmsUser As Outlook.NameSpace
Public newTaskFolder As MAPIFolder
Public WithEvents oTask As Outlook.TaskItem 'definieer een taak
Public WithEvents oTasks As Outlook.Items 'definieer de taken
Public WithEvents oExplorer As Outlook.Explorer
Public WithEvents oApplication As Outlook.Application
Private Sub Application_Startup()
gUser = vbGetUserName()
Initialize_handler
End Sub
Public Sub Initialize_handler()
Dim oNS As Outlook.NameSpace
Set oNS = Application.GetNamespace("MAPI")
If gUser = "Marco" Then
Set newTaskFolder =
oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks).Folders("Taken
Oud")
Set oTasks =
oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks).Items
End If
Set oExplorer = Application.ActiveExplorer
Set oApplication = Outlook.Application
strCurrentUser = gUser
End Sub
Private Sub oExplorer_SelectionChange()
If oExplorer.CurrentFolder.Name = "Taken" Then
If strCurrentUser = "Marco" Then
If oExplorer.Selection.Count <> 0 Then
Set oTask = oExplorer.Selection(1)
sValueRole = oTask.Role
sValueDueDate = oTask.DueDate
sValueSubject = oTask.Subject
End If
End If
End If
End Sub
Private Sub oTasks_ItemChange(ByVal item As Object)
Dim Response As Integer
Dim oTask As TaskItem
Set oTask = item
If Not oTask.Role = "" And Not sValueRole = "" Then
If CDate(oTask.Role) > CDate(sValueRole) Then
oTask.UserProperties("Updater") = strCurrentUser & " " &
Format(Date, "DD-MM-YYYY")
oTask.Save
If (CDate(oTask.Role) = Date - 1 And oTask.DueDate = Date) Or
(CDate(oTask.Role) = Date And oTask.DueDate = Date) Then
'wil je de taak afvinken?
Response = MsgBox("Wil je deze taak afvinken '" &
oTask.Subject & "'?", vbYesNo, "Doorgaan")
If Response = 6 Then
oTask.Status = olTaskComplete
oTask.Save
End If
End If
End If
End If
End Sub
What I'm asking is:
1. when using these tasks with four users on different machines how can
the code tell who is updating the task?
2. why does Outlook get in a loop when I update and complete one task?
Regards
Marco
The Netherlands