Joshua Stafford
Joshua Stafford

Reputation: 635

How do I send a meeting request with one recipient's busy status out of office and one shown as free

I want to send out a meeting invite to the associateEmail and the branchManagerEmail where the associate's meeting shows as "olOutOfOffice" but the branch manager shows as "olFree".

It looks like the Busy Status property is on the Appointment when I want it on the Recipient.

I know Outlook saves the two values separately because one person can go in and change the value after it's accepted.

Here is what I have so far.

Function SendMeetingRequest(subject As String, location As String, startDateTime As     Date, durationMinutes As Integer, associateEmail As String, branchManagerEmail As String, allDayEvent As Boolean) As Boolean

    On Error GoTo ErrorHandler
    SendMeetingRequest = True
    Dim myOutlook As Object
    Dim myApt As AppointmentItem

    ' Create the Outlook session
    Set myOutlook = CreateObject("Outlook.Application")

    ' Create the AppointmentItem
    Set myApt = myOutlook.CreateItem(olAppointmentItem)     ' Set the appointment properties

    Dim r As recipient
    Set r = myApt.recipients.Add(associateEmail)
    r.Type = OlMeetingRecipientType.olRequired
    Set r = myApt.recipients.Add(branchManagerEmail)
    r.Type = OlMeetingRecipientType.olOptional


    With myApt
        .subject = subject
        .location = location
        .Start = startDateTime
        .duration = durationMinutes
        .MeetingStatus = olMeeting
        .allDayEvent = allDayEvent
        .BusyStatus = olFree
        .ReminderSet = False
        .Save
        .send
    End With

    Exit Function
ErrorHandler:
    MsgBox Err & ": " & Error(Err)
    SendMeetingRequest = False


End Function

Upvotes: 4

Views: 1709

Answers (1)

user5412293
user5412293

Reputation:

Hi try setting the reference to the Outlook library and this code

You can check how to add a reference to a library by looking into this Article What I saw in your code is that you are using outlook constants and I am not sure you are using early binding and so the code cannot recognize the correct value of the constant.

If you look into this link you will see that variable "olBusy" has a value of 2 and "olFree" a value of 0; perhaps the code is not understanding the variable and giving it a default int value of 0 (the free status)

Option Explicit

Function SendMeetingRequest(subject As String, _
                            location As String, _
                            startDateTime As Date, _
                            durationMinutes As Integer, _
                            associateEmail As String, _
                            branchManagerEmail As String, _
                            allDayEvent As Boolean) As Boolean


    Dim myOutlook As Outlook.Application
    Dim myApt As AppointmentItem
    Dim r As recipient

I hope this helps.

    On Error GoTo ErrorHandler
    SendMeetingRequest = True


    ' Create the Outlook session
    Set myOutlook = New Outlook.Application
    Set myApt = myOutlook.CreateItem(olAppointmentItem)     ' Set the appointment properties


    Set r = myApt.Recipients.Add(associateEmail)
    r.Type = OlMeetingRecipientType.olRequired
    Set r = myApt.Recipients.Add(branchManagerEmail)
    r.Type = OlMeetingRecipientType.olOptional


    With myApt
        .subject = subject
        .location = location
        .Start = startDateTime
        .Duration = durationMinutes
        .MeetingStatus = olMeeting
        .allDayEvent = allDayEvent
        .BusyStatus = olBusy
        .ReminderSet = False
        .Save
        .send
    End With

Exit_Handler:

    Exit Function

ErrorHandler:

    MsgBox Err & ": " & Error(Err)
    SendMeetingRequest = False

    Resume Exit_Handler

End Function

Upvotes: 1

Related Questions