Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Outlook Tasks in Access in a public Folder 1

Status
Not open for further replies.

ShawnR

Technical User
May 15, 2002
26
US
Hello All:

I need to create an outlook task through automation in access. I have been successful in doing so with the code below HOWEVER I want to create the task in a public folder and assign the appropriate owner. I can't figure how to naigate to the following folder:

Public folders \ All public folders \ Helpdesk \ Tasks

Where "task" is the folder where i want the task to be create. If you reemember you can't "directly" mark an owner in a private Outlook task you have to go threw the "assigning" of a task. I wan tot post these tasks to a public folder becuse the help fiel mentions that you can assign an owner if the task is in a public folder.

Here is the code i have so far(outlook email is built into this and it works no issue there):

Function fncAddOutlookTask()
Dim OutlookApp As Outlook.Application
Dim OutlookTask As Outlook.TaskItem
Dim OutlookEmail As Outlook.MailItem

Dim TaskString As String
Dim SubjectString As String
Dim CategoryString As String
Dim NotesString As String
Dim BodyString As String

Dim intAnswer As Integer

Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookTask = OutlookApp.CreateItem(olTaskItem)
Set OutlookEmail = OutlookApp.CreateItem(olMailItem)

NotesString = "STARTED" & " " & CallDate & " - " & AgentType & Chr(10) & Chr(10) & Notes
CategoryString = "." & AgentType & ", " & "Production Support"
BodyString = "If you have any questions please call Agent: " & AgentType & Chr(10) & "Thank You."

If Notes <> 0 Then
If Task = False Then
Task = True
If PriorityType = 1 Then
TaskString = &quot;# &quot; & CallID & &quot;P&quot; & &quot; / &quot; & SeverityType & &quot; / &quot; & SubjectType
SubjectString = &quot;# &quot; & CallID & &quot;P&quot; & &quot; / &quot; & SeverityType & &quot; / &quot; & SubjectType & &quot; - Added to Helpdesk Tasks. Please Check.&quot;
With OutlookTask
.Owner = &quot;helpdesk&quot;
.Importance = olImportanceHigh
.Subject = TaskString
.Body = NotesString
.Categories = CategoryString
.Display
End With
intAnswer = MsgBox(&quot;Send Email to Production Support?&quot;, vbYesNo + vbQuestion, &quot;Email about to be sent&quot;)
Select Case intAnswer
Case vbYes
With OutlookEmail
.Recipients.Add (&quot;helpdesk&quot;)
.Subject = SubjectString
.Body = BodyString
.Importance = olImportanceHigh
.Send
End With
End Select
Else
TaskString = &quot;# &quot; & CallID & &quot; / &quot; & SeverityType & &quot; / &quot; & SubjectType
SubjectString = &quot;# &quot; & CallID & &quot; / &quot; & SeverityType & &quot; / &quot; & SubjectType & &quot; - Added to Helpdesk Tasks. Please Check.&quot;
With OutlookTask
.Owner = &quot;helpdesk&quot;
.Subject = TaskString
.Body = NotesString
.Categories = CategoryString
.Display
End With
intAnswer = MsgBox(&quot;Send Email to Production Support?&quot;, vbYesNo + vbQuestion, &quot;Email about to be sent&quot;)
Select Case intAnswer
Case vbYes
With OutlookEmail
.Recipients.Add (&quot;helpdesk&quot;)
.Subject = SubjectString
.Body = BodyString
.Send
End With
End Select
End If
Else
MsgBox &quot;Task already created for this Call ID.&quot; _
, , &quot;Can't Create Duplicate Task&quot;
End If
Else
MsgBox &quot;Task can't be created w/o Notes.&quot; _
, , &quot;Can't Create Task&quot;
End If
End Function

ANY help will be greatly appreciated.


 
I can't experiment with this right now, but I think you need something like this (Outlook 9 type library):
Code:
    Dim OutlookNsp As Outlook.NameSpace
    Dim OutlookFldr As Outlook.MAPIFolder
    Set OutlookNsp = OutlookApp.GetNameSpace(&quot;MAPI&quot;)
    Set OutlookFldr = OutlookNsp.Folders(&quot;Public Folders&quot;).Folders(&quot;All public folders&quot;).Folders(&quot;Helpdesk&quot;).Folders(&quot;Tasks&quot;)
    OutlookFldr.Items.Add OutlookTask
This may not be quite right, so don't get stuck on it. I am pretty sure, however, that it starts with the NameSpace object. Rick Sprague
 
Hi RickSpr:

The last line of code I am a bit Confused as to where to place it. The code now looks like this. You will notice where I have added the text However It gives me an &quot;out of memory error please closed windows...&quot; I can't seem to understand the syntax. Believe me I have looked everywhere.

Any help will be most appreciated!

Code as follows:

Function fncAddOutlookTask()
Dim OutlookApp As Outlook.Application
Dim OutlookTask As Outlook.TaskItem
Dim OutlookEmail As Outlook.MailItem
Dim OutlookNsp As Outlook.NameSpace
Dim OutlookFldr As Outlook.MAPIFolder

Dim TaskString As String
Dim SubjectString As String
Dim CategoryString As String
Dim NotesString As String
Dim BodyString As String

Dim intAnswer As Integer

Set OutlookApp = CreateObject(&quot;Outlook.Application&quot;)
Set OutlookTask = OutlookApp.CreateItem(olTaskItem)
Set OutlookEmail = OutlookApp.CreateItem(olMailItem)
Set OutlookNsp = OutlookApp.GetNamespace(&quot;MAPI&quot;)
Set OutlookFldr = OutlookNsp.Folders(&quot;Public Folders&quot;).Folders(&quot;All Public Folders&quot;).Folders(&quot;Helpdesk&quot;).Folders(&quot;Tasks&quot;)

NotesString = &quot;STARTED&quot; & &quot; &quot; & CallDate & &quot; - &quot; & AgentType & Chr(10) & Chr(10) & Notes
CategoryString = &quot;.&quot; & AgentType & &quot;, &quot; & &quot;Production Support&quot;
BodyString = &quot;If you have any questions please call Agent: &quot; & AgentType & Chr(10) & &quot;Thank You.&quot;

If Notes <> 0 Then
If Task = False Then
Task = True
If PriorityType = 1 Then
TaskString = &quot;# &quot; & CallID & &quot;P&quot; & &quot; / &quot; & SeverityType & &quot; / &quot; & SubjectType
SubjectString = &quot;# &quot; & CallID & &quot;P&quot; & &quot; / &quot; & SeverityType & &quot; / &quot; & SubjectType & &quot; - Added to Helpdesk Tasks. Please Check.&quot;
With OutlookFldr
.Items.Add ([OutlookTask])
With OutlookTask
.Owner = &quot;helpdesk&quot;
.Importance = olImportanceHigh
.Subject = TaskString
.Body = NotesString
.Categories = CategoryString
.Display
End With
End With
intAnswer = MsgBox(&quot;Send Email to Production Support?&quot;, vbYesNo + vbQuestion, &quot;Email about to be sent&quot;)
Select Case intAnswer
Case vbYes
With OutlookEmail
.Recipients.Add (&quot;helpdesk&quot;)
.Subject = SubjectString
.Body = BodyString
.Importance = olImportanceHigh
.Send
End With
End Select
Else
TaskString = &quot;# &quot; & CallID & &quot; / &quot; & SeverityType & &quot; / &quot; & SubjectType
SubjectString = &quot;# &quot; & CallID & &quot; / &quot; & SeverityType & &quot; / &quot; & SubjectType & &quot; - Added to Helpdesk Tasks. Please Check.&quot;
With OutlookFldr
.Items.Add ([OutlookTask])
With OutlookTask
.Owner = &quot;helpdesk&quot;
.Subject = TaskString
.Body = NotesString
.Categories = CategoryString
.Display
End With
End With
intAnswer = MsgBox(&quot;Send Email to Production Support?&quot;, vbYesNo + vbQuestion, &quot;Email about to be sent&quot;)
Select Case intAnswer
Case vbYes
With OutlookEmail
.Recipients.Add (&quot;helpdesk&quot;)
.Subject = SubjectString
.Body = BodyString
.Send
End With
End Select
End If
Else
MsgBox &quot;Task already created for this Call ID.&quot; _
, , &quot;Can't Create Duplicate Task&quot;
End If
Else
MsgBox &quot;Task can't be created w/o Notes.&quot; _
, , &quot;Can't Create Task&quot;
End If
End Function

Thanks!!!
 
Change it to look like this:
Code:
    With OutlookTask
        .Owner = &quot;helpdesk&quot;
        .Importance = olImportanceHigh
        .Subject = TaskString
        .Body = NotesString
        .Categories = CategoryString
    End With
    OutlookFldr.Items.Add OutlookTask
    OutlookTask.Display
[code]
Note that I changed &quot;([OutlookTask])&quot; to &quot;OutlookTask&quot;. That was probably what was giving you the out-of-memory error, though the message was inappropriate. By putting it in parentheses, you may have caused VBA to try to assign OutlookTask's default property, rather than to assign the object. The default property doesn't exist, so VBA got confused.

The other reason the error might have occurred is that you tried to add the task to the folder before you filled in the properties. &quot;.Add&quot; is like the Save and Close button; you'll get an error if some value is invalid.

Even so, I got an error about a bad parameter when I tested this, though I was able to save it by hitting the &quot;Save and Close&quot; button after it displayed. Perhaps you've left out some property setting that's required? Rick Sprague
 
Hi Rik:

I got it working. I did a slight variation on what you presented and was successful. MANY MANY thanx! Here is the code. Works like a charm!

Function fncAddOutlookTask()
Dim OutlookApp As Outlook.Application
Dim OutlookTask As Outlook.TaskItem
Dim OutlookEmail As Outlook.MailItem
Dim OutlookNsp As Outlook.NameSpace
Dim OutlookFldr As Outlook.MAPIFolder

Dim TaskString As String
Dim SubjectString As String
Dim CategoryString As String
Dim NotesString As String
Dim BodyString As String

Dim intAnswer As Integer

Set OutlookApp = CreateObject(&quot;Outlook.Application&quot;)
Set OutlookEmail = OutlookApp.CreateItem(olMailItem)
Set OutlookNsp = OutlookApp.GetNamespace(&quot;MAPI&quot;)
Set OutlookFldr = OutlookNsp.Folders(&quot;Public Folders&quot;).Folders(&quot;All Public Folders&quot;).Folders(&quot;Helpdesk&quot;).Folders(&quot;Tasks&quot;)
Set OutlookTask = OutlookFldr.Items.Add

NotesString = &quot;STARTED&quot; & &quot; &quot; & CallDate & &quot; - &quot; & AgentType & Chr(10) & Chr(10) & Notes
CategoryString = &quot;.&quot; & AgentType & &quot;, &quot; & &quot;Production Support&quot;
BodyString = &quot;If you have any questions please call Agent: &quot; & AgentType & Chr(10) & &quot;Thank You.&quot;

If Notes <> 0 Then
If Task = False Then
Task = True
If PriorityType = 1 Then
TaskString = &quot;# &quot; & CallID & &quot;P&quot; & &quot; / &quot; & SeverityType & &quot; / &quot; & SubjectType
SubjectString = &quot;# &quot; & CallID & &quot;P&quot; & &quot; / &quot; & SeverityType & &quot; / &quot; & SubjectType & &quot; - Added to Helpdesk Tasks. Please Check.&quot;
With OutlookTask
.Owner = &quot;helpdesk&quot;
.Importance = olImportanceHigh
.Subject = TaskString
.Body = NotesString
.Categories = CategoryString
.Display
End With
intAnswer = MsgBox(&quot;Send Email to Production Support?&quot;, vbYesNo + vbQuestion, &quot;Email about to be sent&quot;)
Select Case intAnswer
Case vbYes
With OutlookEmail
.Recipients.Add (&quot;helpdesk&quot;)
.Subject = SubjectString
.Body = BodyString
.Importance = olImportanceHigh
.Send
End With
End Select
Else
TaskString = &quot;# &quot; & CallID & &quot; / &quot; & SeverityType & &quot; / &quot; & SubjectType
SubjectString = &quot;# &quot; & CallID & &quot; / &quot; & SeverityType & &quot; / &quot; & SubjectType & &quot; - Added to Helpdesk Tasks. Please Check.&quot;
With OutlookTask
.Owner = &quot;helpdesk&quot;
.Subject = TaskString
.Body = NotesString
.Categories = CategoryString
.Display
End With
intAnswer = MsgBox(&quot;Send Email to Production Support?&quot;, vbYesNo + vbQuestion, &quot;Email about to be sent&quot;)
Select Case intAnswer
Case vbYes
With OutlookEmail
.Recipients.Add (&quot;helpdesk&quot;)
.Subject = SubjectString
.Body = BodyString
.Send
End With
End Select
End If
Else
MsgBox &quot;Task already created for this Call ID.&quot; _
, , &quot;Can't Create Duplicate Task&quot;
End If
Else
MsgBox &quot;Task can't be created w/o Notes.&quot; _
, , &quot;Can't Create Task&quot;
End If
End Function
 
Good catch! It was careless of me to assume that the MAPIFolder.Items property was an ordinary Collection.

Glad you got it working! Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top