Public Function funOutputAppointmentToOutlook(dtmDate As Date, strSubject As String)
Dim olApp As Object
Dim mNameSpace As Object
Const olFolderCalendar = 9
Const olAppointmentItem = 1
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If Err.Number = 429 Then
Err.Clear
'Outlook is not running; open Outlook with CreateObject
Set olApp = CreateObject("Outlook.Application")
End If
Set mNameSpace = olApp.GetNamespace("MAPI")
'mNameSpace.GetDefaultFolder(olFolderCalendar).display
Dim objOwner As Object
Set objOwner = mNameSpace.CreateRecipient("Outlook")
Dim olApt As Object
Set olApt = olApp.CreateItem(olAppointmentItem)
' Add the Form data to the Appointment Properties
With olApt
' If There is no Start Date or Time on
' the Form use Nz to avoid an error
' Set the Start Property Value
.Start = dtmDate '#1/15/2011 4:13:12 PM# 'Nz(Me.Event_date, "") & " " & Nz(Me.Event_time, "")
.duration = 1 'Nz(180, 0)
' vbNullString uses a little less memory than ""
.Subject = strSubject 'Nz(Me.Venue, "vbnullstring") & " suite " & Nz(Me.Suite, vbNullString) & " REF " & Nz(Me.Reference, vbNullString) & " " & Nz(Me.Bride, vbNullString)
'.Body = "" 'Nz(Me.Chair_covers, vbNullString) & " " & Nz(Me.Description, vbNullString) & " --------(table linen)-------- " & Nz(Me.Description_2, vbNullString) & " --------- Additional Items ----------- " & Nz(Me.Description3, vbNullString) & " other info " & Nz(Me.Other_inf, vbNullString) & " address " & Nz(Me.Address_line1, vbNullString) & " " & Nz(Me.Address_line2, vbNullString) & " " & Nz(Me.Town, vbNullString) & " " & Nz(Me.Postcode, vbNullString) & " tel nos " & Nz(Me.Tel_no, vbNullString) & " " & Nz(Me.Alt_tel_no, vbNullString)
'.Location = "" 'Nz(Me.Venue, vbNullString) & " " & Nz(Me.Suite, vbNullString)
'FROM http://www.snb-vba.eu/VBA_Outlook_external_en.html
CreateObject("Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(9).Items(strSubject).Delete
' Save the Appointment Item Properties
.Save
End With
'olApt.display
Set olApt = Nothing
Set mNameSpace = Nothing
Set olApp = Nothing
End Function