?
Solved

Add outlook task item using MS Access form

Posted on 2008-11-08
5
Medium Priority
?
1,595 Views
Last Modified: 2012-05-05
I have been using other EE posts to attempt adding outlook tasks by using VB in MS Access.  The code I have been trying is attached as a snippet.  The first function works perfectly until I try to change the Subject and Body and Date variables to items on my Access Form.

For example, if I set ".Body = Me!Request" where "request" is a control on my access form, the code doesn't do anything.  It neither fails nor adds the task to my Outlook profile.  If I change it back to something in between quotes, it works again.

The second thing I need to achieve is being able to specify which mailbox or user is going to be assigned the task.  Also in my attached code snippet is "Sub AssignTask".  I can't get this code to do anything at all.

Could someone give me help on combining these two code snippets so that my access form can automatically add a task item to a specific user on our network?  My form has Date, Body, and Subject controls, as well as a control to specify an Active Directory user name.
Function AddOutLookTask()
         Dim appOutLook As Outlook.Application
         Dim taskOutLook As Outlook.TaskItem
         Set appOutLook = CreateObject("Outlook.Application")
         Set taskOutLook = appOutLook.CreateItem(olTaskItem)
      With taskOutLook
          .Subject = "This is the subject of my task"
          .Body = "This is the body of my task."
          .ReminderSet = True
          .ReminderTime = DateAdd("n", 2, Now)  ' Set to remind us 2
                                                ' minutes from now.
          .DueDate = DateAdd("n", 5, Now)       ' Set the due date to
                                                ' 5 minutes from now.
          .ReminderPlaySound = True
           'add the path to a .wav file on your computer.
          .ReminderSoundFile = "C:\Win95\media\ding.wav"
          .Save
      End With
     End Function 
 
Sub AssignTask()
    Dim myItem As Outlook.TaskItem
    Dim myDelegate As Outlook.Recipient
 
    Set MyItem = Application.CreateItem(olTaskItem)
    MyItem.Assign
    Set myDelegate = MyItem.Recipients.Add("Dan Wilson")
    myDelegate.Resolve
    If myDelegate.Resolved Then
        myItem.Subject = "Prepare Agenda For Meeting"
        myItem.DueDate = Now + 30
        myItem.Display
        myItem.Send
    End If
End Sub

Open in new window

0
Comment
Question by:netsmithcentral
  • 3
  • 2
5 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 22918106
Hi, netsmithcentral.

Are you running the code from Outlook or Access?
0
 
LVL 12

Author Comment

by:netsmithcentral
ID: 22918157
The code would run from a module in Access, either by doing a function call on an onclick event, or a macro that does a "Run Code" option.  All of the controls that a user would fill out are on an Access Form within the same DB, and once the button is clicked I would like the Outlook Task to be generated and inserted into the Default Task Folder of somebody's active directory account.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 22918224
"I would like the Outlook Task to be generated and inserted into the Default Task Folder of somebody's active directory account."

That's not possible unless the target recipient has shared their tasks folder with the person running the program.  The code could generate and send a task request to the target recipient.
0
 
LVL 12

Author Comment

by:netsmithcentral
ID: 22918419
That's fine if it just generates the task request and sends it.  I have the ability to make the task folders shared with full permissions to any user on the network also.  The second part of my code snippet is written to send a task request, but it doesn't work.  When I run it nothing happens, it fails to generate the task request at all.
0
 
LVL 76

Accepted Solution

by:
David Lee earned 1500 total points
ID: 22918557
Try these.
Function AddOutLookTask()
    Const olTaskItem = 3
    Dim appOutLook As Outlook.Application
    Dim taskOutLook As Outlook.TaskItem
    Set appOutLook = CreateObject("Outlook.Application")
    Set taskOutLook = appOutLook.CreateItem(olTaskItem)
    With taskOutLook
        .Subject = "This is the subject of my task"
        .Body = "This is the body of my task."
        .ReminderSet = True
        .ReminderTime = DateAdd("n", 2, Now)  ' Set to remind us 2
                                              ' minutes from now.
        .DueDate = DateAdd("n", 5, Now)       ' Set the due date to
                                              ' 5 minutes from now.
        .ReminderPlaySound = True
        'add the path to a .wav file on your computer.
        .ReminderSoundFile = "C:\Win95\media\ding.wav"
        .Display
    End With
End Function
 
Sub AssignTask()
    Const olTaskItem = 3
    Dim appOutLook As Outlook.Application
    Dim myItem As Outlook.TaskItem
    Dim myDelegate As Outlook.Recipient
    Set appOutLook = CreateObject("Outlook.Application")
    Set myItem = appOutLook.CreateItem(olTaskItem)
    myItem.Assign
    Set myDelegate = myItem.Recipients.Add("Dan Wilson")
    myDelegate.Resolve
    If myDelegate.Resolved Then
        myItem.Subject = "Prepare Agenda For Meeting"
        myItem.DueDate = Now + 30
        myItem.Display
        myItem.Send
    End If
    Set myDelegate = Nothing
    Set myItem = Nothing
    Set appOutLook = Nothing
End Sub

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
As a matter of fact, Outlook OST files are of much importance in relation to Exchange mailbox. OST files are independent as they are simply copy of data of a user’s mailbox on Exchange Server. Though, if the server’s status is changed or it is dama…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question