• Add task to outlook (2003)

    Author
    Topic
    #452516

    Hi,

    I am trying to modify the follow codes to add a task to outlook from Access database. Below is the codes that I found:

    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:Win95mediading.wav”
    .Save
    End With
    End Function

    How can I modify the codes above to have the Subject & Body auto populate with the fields on my database form?

    Thanks in advance.

    Regards

    Viewing 0 reply threads
    Author
    Replies
    • #1117537

      Change the lines

      .Subject = "This is the subject of my task"
      .Body = "This is the body of my task."

      to

      .Subject = Me.txtSubject
      .Body = Me.txtBody

      where txtSubject and txtBody are the relevant fields/controls on your form. This assumes that AddOutlookTask is stored in the form’s code module.

      • #1117538

        Thank you so much, Hans.

        One more question, how can I set the reminder from now to 3 days later?

        Regards

        • #1117539

          In the code you quoted,

          .ReminderTime = DateAdd("n", 2, Now)

          “n” is the code for minutes, and 2 the amount. The code for days is “d”, so if you want to set the reminder to 3 days from now:

          .ReminderTime = DateAdd("d", 3, Now)

          See DateAdd Function – Access – Microsoft Office Online.

          • #1117543

            Thanks, Hans.

            Do I have to put both “ReminderTime” & “DueDate” since both are 3 days from now? If I have to, then what’s the difference to the user?

            If I have a field (subMemo) on my subform(subfrmEntry) need added to a task as body, what codes should I put?

            Regards

            • #1117559

              The DueDate is the date the task is supposed to be completed.
              The ReminderTime is the date and time when you want a reminder to pop up. This will usually be before the DueDate, but it’s up to you to decide when.

              If the text of the body is to come from a subform, use

              .Body = Me.subfrmEntry.subMemo

              where subfrmEntry should be the name of the subform as a control on the main form.

            • #1117683

              Thanks, Hans.

              Now I get a really big problem. I have make sure I put the right text control name in the codes, but I get “Compile error” Method or data member not found” as soon as I click the sendreminder button. The yellow highlight on the me.txtfield. However, I have the same codes on another form with same field and I don’t have any problem. The only difference of those two forms is one has subform and another doesn’t. But the fields are the same on both forms. One is data entry form and another is search result form. I did google search and some people said sometime form is corruption. So I recreated a new form with the same fields and I am fine for first 3 times tring. After that, the same error message occurs.

              Any suggestion or idea?

              Thanks in advance.

              Regards

            • #1117684

              That’s a strange problem. You could try the following:
              – Create a blank new database.
              – Import all database objects from the problem database into the new one (using File | Get External Data | Import…)
              – Set the startup options for the new database the same way as they are for the old one (Tools | Startup…)
              – Set the references in the Visual Basic Editor the same way as they are in the old one (Tools | References… in the Visual Basic Editor)

            • #1117692

              Thanks, Hans. I just did as you told.

              I am think that maybe I should put the code into a module outside the form since I uses it in two forms. So I copy the following codes to a new module name as “addOutlookReminder”:

              Option Compare Database
              Option Explicit

              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 = strTaskSubject
              .Body = strTaskBody
              .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:Win95mediading.wav”
              .Save
              End With
              End Function

              Then I added the following to the Click_Event of the button on the form:

              Dim strTaskSubject As String
              Dim strTaskBody As String

              But I don’t know what should I do next in order to pass strTaskSubject & strTaskBody to the function.

              Please help.

              Thanks in advance.

              Regards

            • #1117693

              Just replace the line
              Function AddOUtlookTask()
              with
              Function AddOUtlookTask(strTaskSubject as string, strTaskBody as string)

              You will have to call the function like
              AddOUtlookTask(strTaskSubject, strTaskBody)

              Hope it helps.

            • #1117713

              Thank you so much, Hans.

            • #1117714

              That reply was from patt, not from me…

            • #1117725

              Oops, thank so much for both of your help.

    Viewing 0 reply threads
    Reply To: Add task to outlook (2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: