How to assign an Outlook task with Access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nauticalgent
    New Member
    • Oct 2015
    • 103

    How to assign an Outlook task with Access

    Hello all,

    I am using Access/Office 2010 on a Windows 7 platform.

    What I am trying to do sounds simple: I want to assign an Outlook Task to the individual selected in a form's combo box.

    Here is my code that I took from an MSDN site:

    Code:
    Sub AssignedTech_AfterUpdate()
    Dim myOlApp As New Outlook.Application
    Dim myItem As Outlook.TaskItem
    Dim myDelegate As Outlook.Recipient
    Set MyItem = myOlApp.CreateItem(olTaskItem)
    MyItem.Assign
    [B]Set myDelegate = MyItem.Recipients.Add("Dan Wilson")[/B]
    myDelegate.Resolve
    If myDelegate.Resolved Then
    myItem.Subject = "Prepare Agenda For Meeting"
    myItem.DueDate = Now + 30
    myItem.Display
    myItem.Send
    End If
    End Sub
    I do have the Microsoft Outlook 14.0 Object Library referenced and I got a clean compile prior to running the code.

    When I select the intended recipients name, I get a "Run-Time Error "287" Application-Defined or Object-Defined Error"

    When I debug the code, the portion in bold is the culprit. I have tried different ways of doing this but it doesn't matter what I do, it code tanks at the Recipients.Add line.

    Any suggestions?
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Do you actually have a Recipient named Dan Wilson?

    Comment

    • Nauticalgent
      New Member
      • Oct 2015
      • 103

      #3
      If only that were the reason...

      Comment

      • Nauticalgent
        New Member
        • Oct 2015
        • 103

        #4
        The code is a direct cut and paste from an MSDN site. "Dan Wilson" is what/who they used. I actually substitute it with a valid e-mail address that is in the GAL on our exchange server.

        I took this project home and got it to work as written, sans Dan Wilson.

        I loaded in it on my Mac (BootCamp). Win 7, Office 2016. It worked like a charm. Outlook freaked out and wanted assurance from me on every MyItem.xxxx occurrence, but once allowed it, the task was sent and all was well.

        I was not ready to pop the champagne cork yet, so I went to my trusty Lap top that has Office 2010 and things when well on that platform as well...BUT...it uses Win 10. In other words, I was not able to completely duplicate my working environment.

        However, I am satisfied that the code works and that the issues are local settings in Access and Outlook. Not sure how to start "peeling the onion" but I will get there.

        Hopefully some insight from this site is forthcoming, once they get bast the "Dan Wilson" bit that is....

        Comment

        • twinnyfo
          Recognized Expert Moderator Specialist
          • Nov 2011
          • 3653

          #5
          Nauticalgent,

          Here is the code I use and I don't have any problems with it. However, instead of using the name on the GAL, I use the actual e-mail address. When it comes to using the GAL, names and punctuation must be exact (if I remember correctly).

          Code:
          Private Sub AddAppt_Click()
          On Error GoTo EH
              Dim olApp           As Outlook.Application
              Dim olAppt          As Outlook.AppointmentItem
              Dim dtApptDt        As Date
              Dim strSendTo       As String
              Dim strSubject      As String
              Dim strLocation     As String
              Dim strEMailBody    As String
          
              dtApptDt = Date + 3
              strSendTo = "Mickey@Mouse.com"
              strSubject = "Show up for this meeting"
              strLocation = "My Conference Room"
              strEMailBody = "Y'all better show up, too!"
          
              'Create and Send the Appointment
              Set olApp = CreateObject("Outlook.Application")
              Set olAppt = olApp.CreateItem(olAppointmentItem)
              With olAppt
                  .RequiredAttendees = strSendTo
                  .Subject = strSubject
                  .Location = strLocation
                  .Start = dtApptDt
                  .Duration = 120
                  .ReminderMinutesBeforeStart = 120
                  .ReminderSet = True
                  .Body = strEMailBody
                  .Display
              End With
              Set olAppt = Nothing
              Set olApp = Nothing
          
              Exit Sub
          EH:
              MsgBox "There was an error scheduling the Appointment!  " & _
                  "Please contact your Database Administrator.", vbOKOnly, "WARNING!"
              Exit Sub
          End Sub
          Let me know if this hepps....

          Comment

          • twinnyfo
            Recognized Expert Moderator Specialist
            • Nov 2011
            • 3653

            #6
            Just noticed the title of this post. This is for a Task, not an Appointment. This might be different than the code provided.

            Comment

            Working...