Working with MS Outlook

R

Rob

Hi all,

I am not sure if this is the right group, but I have an issue when
automating tasks between Access and Outlook.

The issue relate to the warning box that Outlook displays. I have the
following code to add and retreive tasks:

Public Function AddTaskToOutlook(strSubject As String, dtDueDate As Date,
Optional strBody As String, Optional dtReminder As Date)

Dim appOutlook As Outlook.Application
Dim appTask As Outlook.TaskItem
Dim i As Integer

Set appOutlook = New Outlook.Application
Set appTask = appOutlook.CreateItem(olTaskItem)

With appTask
.Subject = strSubject
.DueDate = dtDueDate
If strBody <> vbNullString Then
.Body = strBody
End If
If dtReminder Then
.ReminderTime = dtReminder
.ReminderSet = True
.ReminderPlaySound = True
End If
.Save
End With

Set appTask = Nothing
Set appOutlook = Nothing
End Function

and

Public Function GetOutlookTaskData(strID As String) As Variant

Dim appOutlook As Outlook.Application
Dim appNameSpace
Dim appTasksFolder
Dim appTasks As Outlook.Items
Dim appTask As Outlook.TaskItem
Dim i As Integer
Dim varRtn As Variant
Dim strSubject As String

Set appOutlook = New Outlook.Application
Set appNameSpace = appOutlook.GetNamespace("MAPI")
Set appTasksFolder = appNameSpace.GetDefaultFolder(olFolderTasks)
Set appTasks = appTasksFolder.Items


For i = 1 To appTasks.Count
Set appTask = appTasks(i)
strSubject = appTask.Subject
If InStr(strSubject, strID) <> 0 Then
'varRtn = adhPutItem(varRtn, "Body", appTask.Body)
varRtn = adhPutItem(varRtn, "DueDate", appTask.DueDate)
varRtn = adhPutItem(varRtn, "Subject", strSubject)
End If
Set appTask = Nothing
Next

GetOutlookTaskData = varRtn

Set appTasks = Nothing
Set appTasksFolder = Nothing
Set appNameSpace = Nothing
Set appOutlook = Nothing

End Function

The AddTaskToOutlook function works as expected, and I do not receive any
warning boxes. When I run the GetOutlookTaskData function Outlook displays
the warning box and asks for access only when I try and access the Body
property of the TaskItem. I was wondering why there is a difference between
the two functions.

Cheers
Rob
 
R

Rob

Hi all,

Reading the help file *properly* this time I have found the reason for my
problem! It seems that the Body property is protected, and it seems I will
always get security warning when using CreateObject to use Outlook. This
function is not used that often, and as other applications on our system
throw the same warning, users should be comfortable with it.

Cheers
Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top