Public Sub sAddAppointment(datFromDate As Date, datToDate As Date, strCatCode As String, strHalfDay As String, strComment As String)
' Subroutine to add a new appointment to the Outlook calendar
' Parameters brought in: datFromDate - Start date of event
' datToDate - End date of event
' strCatCode - Event type (H, S, SL etc..)
' strHalfDay - AM or PM
' strComment - Any comment, i.e. Excel Course
Dim outApp As Outlook.Application ' An instance of Outlook
Dim outAppoint As Outlook.AppointmentItem ' An appointment
Dim strCategory As String ' The full category name (i.e. Holiday)
strCategory = DLookup("[Full Cat]", "tblCategories", "[Short Code] = '" & strCatCode & "'")
Set outApp = New Outlook.Application
Set outAppoint = outApp.CreateItem(olAppointmentItem)
With outAppoint
If strHalfDay = "" Then ' If not a half day
.Start = datFromDate
If datToDate > datFromDate Then .End = datToDate + 1
.AllDayEvent = True
ElseIf strHalfDay = "AM" Then ' If half day (morning)
.Start = datFromDate & " 09:30:00 AM"
.Duration = 210
ElseIf strHalfDay = "PM" Then ' If half day (afternoon)
.Start = datFromDate & " 02:00:00 PM"
.Duration = 210
End If
If strComment <> "" Then .Subject = strCategory & " (" & strComment & ")" Else .Subject = strCategory
.BusyStatus = olOutOfOffice
.ReminderSet = False
.Body = "Added to your calendar by " & strThePNamE & " - " & Date
.Save
End With
Set outAppoint = Nothing
Set outApp = Nothing
End Sub