Generate MS Outlook Task Based on Date Text Box in Access Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bkyzer
    New Member
    • Aug 2012
    • 11

    Generate MS Outlook Task Based on Date Text Box in Access Form

    I'd like to use a checkbox with the necessary VBA code that when checked, it would fire a MS Outlook task to the recipient based on some fields in a form that I have.

    My form is called All Details. I'd like the email to be sent to the reciepient's email address that is in the cboassignedto field and have the task created based on the txtduedate_deta il txt box that has the date. I'd like for the VBA code to set a reminder for 2 days if the txtduedate is greater than 2 days from today.

    I really don't know where I need to get started with this task so some guidance for someone learning is much appreciated.

    Thanks in advance!
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3653

    #2
    bkyzer,

    I don't know if creating a task is possible, but I know you can set up appointments in VBA. Here is some sample code to get started:


    Code:
    Option Compare Database
    Option Explicit
    
    Public Function CreateAppointment(SubjectStr As String, BodyStr As String, StartTime As Date, EndTime As Date, AllDay As Boolean)
    On Error Goto EH
        Dim OlApp As Outlook.Application
        Dim Appt As Outlook.AppointmentItem
        Set OlApp = CreateObject("Outlook.Application")
        Set Appt = OlApp.CreateItem(olAppointmentItem)
        Appt.Subject = SubjectStr
        Appt.Start = StartTime
        Appt.End = EndTime
        Appt.AllDayEvent = AllDay
        Appt.BOdy = BodyStr
        Appt.Save
        Set Appt = Nothing
        Set OlApp = Nothing
        Exit Function
    EH:
        MsgBox Err.Number & " " & Err.Description
        Exit Function
    End Function

    You would call this Function from elsewhere within your code like this:

    Code:
    Private Sub cmdButton_Click()
         CreateAppointment "John Test", "This is the body", Now(), Now + 1, True
    End Sub
    I hope this gets you pointed in the right direction.....

    Comment

    • bkyzer
      New Member
      • Aug 2012
      • 11

      #3
      Thanks for the insight. If Tasks are a no-go I'll try to go with this appointment option. I get that I need to put the subroutine behind my control, however, how do I need to build the Function that is your first set of code?

      Thanks for the help as I'm self-taught one all of this and I wish I could do some formal training.

      Comment

      • twinnyfo
        Recognized Expert Moderator Specialist
        • Nov 2011
        • 3653

        #4
        No problems.... I am completley self-taught, too. But, I do recommend taking some time to learn in a formal setting, as you will learn some of the basic principles of databases that you could only learn after much trial and error on your own....

        For the first part of my code, I would place that in a separate module (I always have a module in my Access projects called modSystem, that contains all my public functions and subroutines). Then, on your form, you can set the addressees for the appointment and set other criteria for the appointment and have a command button on the form which executes the function as depicted in my second portion of code. All of the arguments for that code would be based on the text boxes on your form.

        I hope this helps.

        Comment

        • zmbd
          Recognized Expert Moderator Expert
          • Mar 2012
          • 5501

          #5
          And here's how

          Take a look at this:

          Explore the latest news and expert commentary on IT Management brought to you by the editors of ITPro Today



          Other information:



          Comment

          Working...