Get Task ID

Q

Question Boy

I am using the following bit of code to create a task in Outlook from Access

Dim olApp As Outlook.Application
Dim olTask As Outlook.TaskItem
Set olApp = CreateObject("Outlook.Application")
Set olTask = olApp.CreateItem(olTaskItem)
With olTask
.Subject = sSubject
.Body = sBody
'Reminder Settings
.ReminderSet = True
'Remind 2 hours prior to the due date
.ReminderTime = DateAdd("n", -120, DueDt)
'.ReminderPlaySound = True
'.ReminderSoundFile = "C:\WINNT\Media\Ding.wav"
'Due Date Settings
.DueDate = DueDt
Debug.Print
.Save
End With

Set olTask = Nothing
Set olApp = Nothing

I would need some help because the user can change the due date and as such
I need to be able to edit the task once it is created. Thus, I thought and
you can tell me otherwise, that at creation time I would return the Task
EntryId and store it with the database data and if changes occur use it to
reference the task and apply changes.

The problem is that I have tried to get the EntryID and it is always empty?
Is my approach wrong or am I doing something wrong?

Thank you

QB
 
K

Ken Slovak - [MVP - Outlook]

EntryID is only valid for an item when it's saved. Before that the EntryID
is null string or empty.
 
Q

Question Boy

As such, should I not have been able to get the EntryID after the .save?
Such as:

.DueDate = DueDt
.Save
TaskId = .EntryId
End With

Why does this not work? What is the proper method then?

QB
 
Q

Question Boy

I have gone to the extent of trying

.DueDate = DueDt
Debug.Print "'" & .EntryID & "'"
.Save
Debug.Print "'" & .EntryID & "'"
End With

Debug.Print "'" & olTask.EntryID & "'"

Set olTask = Nothing
Set olApp = Nothing

And it returns
''
''
''

It never seems to get an EntryId value?

QB
 
Q

Question Boy

I did further testing and discovered that it returns an EntryId if Outlook is
already open and running. However, if my code launches outlook to add the
task and closes, it never returns a value?

Any ideas as to why?

QB
 
Q

Question Boy

Here is my full function
************
Const olTaskItem = 3
Dim olApp As Object
Dim olTask As Object

On Error Resume Next
'Use late binding to connect to Outlook
Set olApp = GetObject(, "Outlook.Application")

If olApp Is Nothing Then
Err.Clear
Set olApp = CreateObject("Outlook.Application")
End If

On Error GoTo Error_Handler
Set olTask = olApp.CreateItem(olTaskItem)
DoEvents
With olTask
.Subject = sSubject
.Body = sBody
'Reminder Settings
.ReminderSet = True
'Remind 2 hours prior to the due date
.ReminderTime = DateAdd("n", -120, DueDt)
'.ReminderPlaySound = True
'.ReminderSoundFile = "C:\WINNT\Media\Ding.wav"
'Due Date Settings
.DueDate = DueDt
.Save
End With
DoEvents
Debug.Print "'" & olTask.EntryID & "'"

Set olTask = Nothing
Set olApp = Nothing
*****************

What I have noticed is that if Outlook is running when it is executed, it
works fine and returns an EntryID. However, if Outlook is not running, it
appears to launch outlook prompting me to specify the profile to use, then
that's it and does not actually add the task nor return any EntryId.

Anyone see what I am doing wrong?!

Thank you,

QB
 
Q

Question Boy

Revision to my previous statement. I just noticed that it is true that if
Outlook is launch by my function the task does not appear in the task list,
but if I open Outlook and wait 1-2minutes all of a sudden the task will
appear?!

I am lost, what the heck is going on? Why the delayed reaction? Where is
the virtual task being stored?

QB
 
D

Dmitry Streblechenko

Outlooks tries to be "smart" and delays implicitly logging to a MAPI profile
for as long as possible. This creates nothing but problems.
Callign Namespace.Logon ensures that there is a valid MAPI session. If
Outlook aleready has a MAPI session, that line will do nothing.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 

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