locked
Create Outlook task from Access VBA RRS feed

  • Question

  • I want to write a program in Access (Office 365) that goes through a table containing due dates and creates a task for me on each of the due dates.  Here is the code I wrote.

    Public Sub AddTasks()
    Dim tbl As Recordset
    Dim rst As Recordset
    Dim lngYearID As Long
    Dim dteEndOfPeriod As Date
    Dim myOutlook As Outlook.Application
    Dim myTask As TaskItem
    Set myOutlook = CreateObject("outlook.application")
    Set myTask = myOutlook.CreateItem(olTaskItem)
    With CurrentDb
        Set tbl = .OpenRecordset("PayPeriods")
        Set rst = .OpenRecordset("PayPeriodsWithDates")
    With tbl2
        .Index = "YearID"
        lngYearID = 1
        .Seek "=", lngYearID
        Do While !YearID = lngYearID
            lngPayPeriodID=!PayPeriodID

            With rst     

                .FindFirst "PayPeriodID=" & lngPayPeriodID
                dteEndOfPeriod = !EndOfPeriodDate
            End With
            With myTask
                .Subject = "Get custodians' hours"
                .DueDate = dteEndOfPeriod
                .Assign
                .Recipients.Add StaffEmail("Treasurer")
                .Send
            End With
            .MoveNext
            If .EOF Then
                Exit Do
            End If
        Loop
    End With
    End Sub

    When I run the code, I get an error that I cannot assign a task to myself (I am the treasurer.  StaffEmail is a function I created that returns the email address of the title inputted).  I tried removing the .Assign line, but I got another error.  In the past, I have entered the tasks manually in Outlook for each day that hours are due in payroll.  How do I create the task for myself?  I don't need to assign it to anyone else.  Thanks.



    Jill Marlow

    Wednesday, January 9, 2019 4:54 PM

Answers

  • Hi Jill,

    Could you try Daniel's code just to see if it will work for you? If so, then my guess is when assigning a task to yourself, perhaps you don't need to use an email address.

    • Marked as answer by Jill Marlow Thursday, January 10, 2019 8:28 PM
    Wednesday, January 9, 2019 5:45 PM

All replies

  • Hi Jill,

    Could you try Daniel's code just to see if it will work for you? If so, then my guess is when assigning a task to yourself, perhaps you don't need to use an email address.

    • Marked as answer by Jill Marlow Thursday, January 10, 2019 8:28 PM
    Wednesday, January 9, 2019 5:45 PM
  • It worked perfectly!  Thank you!

    Jill Marlow

    Thursday, January 10, 2019 8:28 PM
  • Hi Jill,

    Congratulations! Glad to hear you got it to work. Good luck with your project.

    Thursday, January 10, 2019 8:52 PM