I want to reduce my 99% down to 80% as I see in my code I am using a trusted outlook application object. I have a hack in which I have an Outlook addin and it has a "safe" outlook object. I call that addin from access to give me that Outlook application object, everything that is built off of that object is trusted. (Don't worry to much about this as it is truly a hack - I just dislike redemption and the like.)I am 99% sure that Task.Recipients.add ("noddyandbigears@toytown.com") does not offend any standard security settings.
maybe my suggestions were confusing so I have put an example. There might be a few typos as I did not compile it as I was using a text editor.
Code:
Private Function addOutlookTask(dt_startdate As Date, _
dt_enddate As Date, _
str_body As String, _
str_userprop As String, _
str_subject As String) As Boolean
Dim olApp As Outlook.Application
Dim oNS As Outlook.Namespace
Dim oTask As Outlook.TaskItem
Dim dt_remindertime As String
On Error Resume Next 'this is only needed in the beginning if GetObject fails. You need to change after to another error handler.
Set olApp = GetObject(, "Outlook.Application")
If Err.Number = 429 Then
Set olApp = CreateObject("Outlook.Application")
Set oNS = olApp.GetNamespace("MAPI")
oNS.Logon "", "", False, True
End If
'set the task from the application object.
Set oTask = olApp.CreateItem(olTaskItem)
With oTask
.startDate = Format(dt_startdate, "Short Date") & " " & Format("9.00", "Short Time")
.DueDate = Format(dt_enddate, "Short Date") & " " & Format("17.00", "Short Time")
.Status = olTaskInProgress
'I am copying from some old code of mine so I also set a remnder time. You can remove this.
'this bit of code just sets a reminder time BEFORE the due date and makes sure it is not on a weekend.
If DateDiff("d", .startDate, .DueDate) > 5 Then
dt_remindertime = Format((DateAdd("d", (Int(0.75 * DateDiff("d", .startDate, .DueDate))), .startDate)), "Short Date") & _
" " & Format("9.00", "Short Time")
Select Case Weekday(dt_remindertime, vbMonday)
Case 6
dt_remindertime = DateAdd("d", -1, dt_remindertime)
Case 7
dt_remindertime = DateAdd("d", -2, dt_remindertime)
End Select
Else
dt_remindertime = DateAdd("d", -2, .DueDate)
End If
'I like to be able to find my tasks as I also delete. I therefore add a Userproperty to the task and a unique
'ID that is saved in a table.
.UserProperties.add "FindMyTaskTag", olNumber, True
.UserProperties.item("FindMyTaskTag").Value = str_userprop
.ReminderSet = True
.ReminderTime = dt_remindertime
.subject = str_subject
.body = str_body
.Owner = "noddyandbigears@toytown.com"
.Recipients.add ("noddyandbigears@toytown.com")
.Recipients.add ("mrPlod@toytown.com")
.assign
.display (False)
End With
End Function