Hello, I'm trying to write a vba function to retrieve a task that I place in the task folder through vba.
Here is the code to place the task. This code is in an Access 2002 db program.
Code:
Function fncAddOutlookTask(TaskSubject As String, TaskBody As String, TaskDueDate As Date, _
TaskReminder As Boolean)
Dim OutlookApp As Outlook.Application
Dim OutlookTask As Outlook.TaskItem
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookTask = OutlookApp.CreateItem(olTaskItem)
With OutlookTask
.Subject = TaskSubject
.Body = TaskBody
.DueDate = TaskDueDate
.ReminderSet = TaskReminder
.ReminderPlaySound = True
.ReminderSoundFile = "C:\Windows\Media\Ding.wav" 'Modify path.
.Save
End With
End Function
Here is the code I am using to retrieve the task.
Code:
Function fncRetrieveOutlookTask(TaskSubject As String)
Dim OutlookApp As Outlook.Application
Dim MyTaskList As Outlook.Items
Dim MyTask As TaskItem
Set OutlookApp = CreateObject("Outlook.Application")
Set MyTaskList = OutlookApp.GetNamespace("MAPI").GetDefaultFolder(olFolderTasks). _
Items.Restrict("[Subject] Like '" & TaskSubject & "*'")
If MyTaskList.Count = 1 Then
Set MyTask = MyTaskList.Item(0)
Debug.Print MyTask.Subject & " - " & MyTask.CreationTime
Else
For Each MyTask In MyTaskList
Debug.Print MyTask.Subject & " - " & MyTask.CreationTime
Next
End If
End Function
I want to use the restrict method to pair down the number of tasks and the find the right one. As you can see I have used the "Like" conditional statement, but I keep getting an error with it.
Any ideas?
Thanks
Mark