Link to home
Start Free TrialLog in
Avatar of netsmithcentral
netsmithcentralFlag for United States of America

asked on

Add outlook task item using MS Access form

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

Avatar of David Lee
David Lee
Flag of United States of America image

Hi, netsmithcentral.

Are you running the code from Outlook or Access?
Avatar of netsmithcentral

ASKER

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.
"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.
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.
ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial