Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Outlook Appointments

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
GB
Is there any code that will allow me to add appointments to outlook without having to reference the outlook library. I can do it with sending emails but I need it to add appointments.

The people I am designing a database for dont have access so I am packaging it in runtime and it throws up the missing outlook library file

 
This is the code I have to add an appointment to outlook. Now it works in an mdb file, however when trying it from an adp (sql server backend) i get the error message

Code:
Type mismatch

on the line
Code:
.Start = Me!AppointmentDate & " " & Me!AppointmentTime

I am thinking its something to do with the time but I am not 100% sure.

Code:
Private Sub cmdAddAppointment_Click()
On Error GoTo Add_Err

    'Save record first to be sure required fields are filled.
    DoCmd.RunCommand acCmdSaveRecord

    'Exit the procedure if appointment has been added to Outlook.
    If Me!AddedToOutlook = True Then
        MsgBox "This appointment is already added to Microsoft Outlook"
        Exit Sub
    'Add a new appointment.
    Else
        Dim objOutlook As Outlook.Application
        Dim objAppointment As Outlook.AppointmentItem
        Dim objRecurPattern As Outlook.RecurrencePattern

        Set objOutlook = CreateObject("Outlook.Application")
        Set objAppointment = objOutlook.CreateItem(olAppointmentItem)

        With objAppointment
            .Start = Me!AppointmentDate & " " & Me!AppointmentTime
            .Duration = Me!AppointmentLength
            .Subject = Me!Appointment

            If Not IsNull(Me!AppointmentNotes) Then .Body = Me!AppointmentNotes
            If Not IsNull(Me!AppointmentLocation) Then .Location = Me!AppointmentLocation
            If Me!AppointmentReminder Then
                .ReminderMinutesBeforeStart = Me!ReminderMinutes
                .ReminderSet = True
            End If

            'Set objRecurPattern = .GetRecurrencePattern
            
            'With objRecurPattern
                '.RecurrenceType = olRecursWeekly
               ' .Interval = 1
                'Once per week
               ' .PatternStartDate = #7/9/2003#
                'You could get these values
                'from new text boxes on the form.
                '.PatternEndDate = #7/23/2003#
            'End With

            .Save
            .Close (olSave)
            End With
            'Release the AppointmentItem object variable.
            Set objAppointment = Nothing
    End If

    'Release the Outlook object variable.
    Set objOutlook = Nothing

    'Set the AddedToOutlook flag, save the record, display a message.
    Me!AddedToOutlook = True
    DoCmd.RunCommand acCmdSaveRecord
    MsgBox "Appointment Added!"

    Exit Sub

Add_Err:
    MsgBox "Error " & Err.Number & vbCrLf & Err.Description
    Exit Sub

End Sub
 
That works perfectly. Thank you

Any reason why it adds the appointment two days after the date entered into the date field?

Also, which code to I change to make it late binding so I am not using the reference library. I have seen it around somewhere but cant find it again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top