Morning Darbid,
I hope you are well. I've tried what you have suggested and now i get
Run-time error '91': Object variable or with block variable not set
It highlights this line "Set objNS = objApp.GetNamespace("MAPI")"
Thanks for your help again!!
Private Sub AddAppt_Click()
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder 'get name of other persons folder
Dim objRecip As Outlook.Recipient 'other persons name
Dim strName As String 'the name or email of the persons folder
Dim objAppt As Outlook.AppointmentItem
Dim objApp As Outlook.Application
'On Error Resume Next
' ### name of person whose Calendar you want to use ###
strName = Me.Assigned_to.Value
'This example assume that the Outlook object is already alive.
Set objNS = objApp.GetNamespace("MAPI")
Set objRecip = objNS.CreateRecipient(strName)
If Not objRecip.Resolve Then
MsgBox "We have a problem"
End If
Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)
If Not objFolder Is Nothing Then
Set objAppt = objFolder.Items.Add
If objAppt Is Nothing Then
Set objAppt = objApp.CreateItem(olAppointmentItem)
End If
End If
With objAppt
.Start = Format(Me.ApptDate, "Short Date") & " " & Format(Me.ApptTime, "Short Time")
.End = Format(Me.ApptEnd, "Short Date") & " " & Format(Me.ApptEndTime, "Short Time")
.Location = Me.ApptLocation
.Subject = Me.Appt
.MeetingStatus = olMeeting
.ReminderMinutesBeforeStart = 20
.BusyStatus = olBusy
.Recipients.ResolveAll
.Save
.Display
End With
Set objNS = Nothing
Set objFolder = Nothing
Set objRecip = Nothing
Set objApp = Nothing
'dont forget to also set outlook to nothing. Also do the Outlook object last. Outlook will not close properly otherwise.
End Sub