Question : 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.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
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

Answer : Add outlook task item using MS Access form

Try these.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
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
Random Solutions  
 
programming4us programming4us