Assign Outlook Task Item loop (1 Viewer)

darbid

Registered User.
Local time
Today, 18:47
Joined
Jun 26, 2008
Messages
1,428
I am 99% sure that Task.Recipients.add ("noddyandbigears@toytown.com") does not offend any standard security settings.
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.)

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
In my opinion this should cause no warnings of a security type, but if it does then only the outlook "Object Model Guard" type as shown here. http://www.outlookcode.com/article.aspx?id=52
 

vbaInet

AWF VIP
Local time
Today, 17:47
Joined
Jan 22, 2010
Messages
26,374
I understand that it's a pretty long thread and hard to follow but let me re-cap for your benefit.

Application.Recipients wasn't used and if it was it was just a test. In post #7 we're adding a recipient to the task using Task.Recipients.Add. Other variations of this were also tried. Set recipientObj = Task.Recipients.Add() adds a recipient and sets a reference to the newly added Recipient, it's not an Applications.Recipients reference. But it still failed when it tried to add a recipient to the task.
spikepl then suggested adding the recipient before assigning the task (which you're suggesting), which he did but got the same error message.

All the code you see about CurrentUser and namespace were simply tests, even the Logon method was incorporated at some point.

It was then concluded after further research that access to the recipient was being blocked. So whether you call Application.Recipients or Task.Recipients, both references are a reference to the user's recipients and MS are clever enough to put a block on it. With the security setting Now this is where the security setting comes into play. Have a read:

http://www.msoutlook.info/question/883

It also states on there that from Outlook 2007, if an active anti-virus is installed you will not get a security prompt telling you that it was blocked because the anti-virus deals with it, it will just be blocked. So any attempt to bring the explorer/inspector window up to see if you will see a security prompt is futile.

A task is an object, whether you add a recipient first before assigning the task, or you assign the task then add and resolve your recipient afterwards shouldn't make a difference, as long as it's done through the same Task object. Either way, you're dealing with the same task object.

You do make some good points about adding an owner and setting status (and all the other good stuff), but what we were doing here was to first be able to send tasks and then all the other good stuff can follow.

I hope you understand.
 

vbaInet

AWF VIP
Local time
Today, 17:47
Joined
Jan 22, 2010
Messages
26,374
(Don't worry to much about this as it is truly a hack - I just dislike redemption and the like.)
Yes, Redemption was also suggested, I just didn't have time to re-code the whole thing. If you've got some code it would be useful.
 

darbid

Registered User.
Local time
Today, 18:47
Joined
Jun 26, 2008
Messages
1,428
Yes, Redemption was also suggested, I just didn't have time to re-code the whole thing. If you've got some code it would be useful.

Yep code added. Note there is no "Set recipient" in there and no resolve. I think if you display the task with the email addresses, then when you click send, it will do the recipient stuff at that stage which is how Outlook normally does things when you type an email address.
 

vbaInet

AWF VIP
Local time
Today, 17:47
Joined
Jan 22, 2010
Messages
26,374
Set shouldn't affect it, because it's only setting a reference to the newly added recipient, but yeah we also tried just adding the Recipient without the set but it failed.

Some useful additions in your code too. See how it goes anyway.
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 12:47
Joined
Apr 27, 2015
Messages
6,341
I have read this thread in its entirety. I cannot determine if there was a resolution or not. I will be attempting to do something like this today and I PRAY I do not run into the same issues.

So...was there a "eureka" moment or did this just lose steam?
 

Users who are viewing this thread

Top Bottom