Results 1 to 13 of 13
  1. #1
    4 Star Lounger
    Join Date
    Feb 2006
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Add task to outlook (2003)

    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

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Add task to outlook (2003)

    Change the lines
    <code>
    .Subject = "This is the subject of my task"
    .Body = "This is the body of my task."
    </code>
    to
    <code>
    .Subject = Me.txtSubject
    .Body = Me.txtBody
    </code>
    where txtSubject and txtBody are the relevant fields/controls on your form. This assumes that AddOutlookTask is stored in the form's code module.

  3. #3
    4 Star Lounger
    Join Date
    Feb 2006
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Add task to outlook (2003)

    Thank you so much, Hans.

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

    Regards

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Add task to outlook (2003)

    In the code you quoted,
    <code>
    .ReminderTime = DateAdd("n", 2, Now)
    </code>
    "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:
    <code>
    .ReminderTime = DateAdd("d", 3, Now)
    </code>
    See DateAdd Function - Access - Microsoft Office Online.

  5. #5
    4 Star Lounger
    Join Date
    Feb 2006
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Add task to outlook (2003)

    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

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Add task to outlook (2003)

    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
    <code>
    .Body = Me.subfrmEntry.subMemo
    </code>
    where subfrmEntry should be the name of the subform as a control on the main form.

  7. #7
    4 Star Lounger
    Join Date
    Feb 2006
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Add task to outlook (2003)

    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

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Add task to outlook (2003)

    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)

  9. #9
    4 Star Lounger
    Join Date
    Feb 2006
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Add task to outlook (2003)

    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

  10. #10
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Add task to outlook (2003)

    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.

  11. #11
    4 Star Lounger
    Join Date
    Feb 2006
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Add task to outlook (2003)

    Thank you so much, Hans.

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Add task to outlook (2003)

    That reply was from <!profile=patt>patt<!/profile>, not from me...

  13. #13
    4 Star Lounger
    Join Date
    Feb 2006
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Add task to outlook (2003)

    Oops, thank so much for both of your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •