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

LVL 12
netsmithcentralAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David LeeCommented:
Hi, netsmithcentral.

Are you running the code from Outlook or Access?
0
netsmithcentralAuthor Commented:
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
David LeeCommented:
"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
netsmithcentralAuthor Commented:
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
David LeeCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.