INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Creating Outlook calendar items in an iCloud folder

Creating Outlook calendar items in an iCloud folder

(OP)
I have a CRM type of application that manages contracts for an entertainment business. One of the functions creates a calendar object in Outlook. This has been running just fine for a long time. I am trying to implement synchronization via iCloud to my phone and tablet.

Unfortunately, this means that there is no longer any data calendar or contact data kept in the default Outlook folder. I need to change the coding to select this different folder that iCloud uses.

It appears that the folder is seen by the VBA code, but I am missing the key part to actually create the object here.

The relevant code currently in use follows. I have heavily annotated the code to indicate where I am digressing from the working code.

Any assistance would be greatly appreciated.

Private Sub updateOutlookAppointment()
Dim objOutlook As New Outlook.Application
Dim objCalendar As MAPIFolder
Dim objNameSpace As Outlook.NameSpace
Dim objCalendarItems As Outlook.Items
Dim objAppointment As Outlook.AppointmentItem

Dim folderName As String
Dim foundFolder As Folder

' The next two lines should be fine because they deal with higher level objects
Set objOutlook = CreateObject("Outlook.Application")
Set objAppointment = objOutlook.CreateItem(olAppointmentItem)

' OK, not sure about the next line in the iCloud side of things
Set objNameSpace = objOutlook.GetNamespace("MAPI")

' The problem starts here. objNameSpace needs to access the iCloud instance of the folder
Set objCalendar = objNameSpace.GetDefaultFolder(olFolderCalendar)

'Found this code in a forum somewhere and it does appear to find the iCloud folder

folderName = "iCloud"
Set FoundFouder = FindInFolders(objOutlook.Session.Folders, folderName)

If Not FoundFouder Is Nothing Then
Set objOutlook.ActiveExplorer.CurrentFolder = FoundFouder
Else
MsgBox "Folder: " & folderName & " Not Found", vbInformation
End If

'*** I have no idea how to get from the found folder to the creation of objCalendarItems.

'This next one should be fine, once we have the correct calendar
Set objCalendarItems = objCalendar.Items

'The following code should work IF the correct folder/calendar is pointed to!!
Set curdb = CurrentDb

strWhereCond = "SELECT * FROM Entertainment WHERE ReferenceNo = " & Me!ReferenceNo

Set entertainmentRst = curdb.OpenRecordset(strWhereCond)

Do While Not entertainmentRst.EOF
' There is one entertainment record for each booking day of an event

strWhere = "[Reference] = " & Me!ReferenceNo & _
" AND [Line] = " & entertainmentRst!LineNo

chrStartDateTime = FormatDateTime(entertainmentRst!ShowDate, vbShortDate) & " " & _
FormatDateTime(entertainmentRst!StartTime, vbLongTime)
chrEndDateTime = FormatDateTime(entertainmentRst!ShowDate, vbShortDate) & " " & _
FormatDateTime(entertainmentRst!EndTime, vbLongTime)

Set objAppointment = objCalendarItems.Find(strWhere)

doAppointment = True

If Me!BookingStatus = "CAN" And Not objAppointment Is Nothing Then
With objAppointment
.Delete
End With

doAppointment = False
End If

If entertainmentRst!ShowDate < Now - 7 Then
doAppointment = False
End If

If objAppointment Is Nothing And doAppointment = True Then
' Create the appointment
Set objAppointment = objCalendar.Items.Add(olAppointmentItem)

With objAppointment
Set objOutlookProperties = objAppointment.UserProperties

Set objAppointmentProperty = objOutlookProperties.Add("Reference", olNumber, True, 1)
objAppointmentProperty.Value = Me!ReferenceNo

Set objAppointmentProperty = objOutlookProperties.Add("Line", olNumber, True, 1)
objAppointmentProperty.Value = entertainmentRst!LineNo

.Save
End With
End If

' There's a lot more stuff beyond this, but it's just setting up the notes section of the calendar entry.

RE: Creating Outlook calendar items in an iCloud folder

Quote:


' The problem starts here. objNameSpace needs to access the iCloud instance of the folder
Set objCalendar = objNameSpace.GetDefaultFolder(olFolderCalendar)

'Found this code in a forum somewhere and it does appear to find the iCloud folder

folderName = "iCloud"
Set FoundFouder = FindInFolders(objOutlook.Session.Folders, folderName)


Notice how the red objects are not the same and therefore not a fix to your code.
Obviously you will need to comment out the original Outlook version.

RE: Creating Outlook calendar items in an iCloud folder

(OP)
I missed the typo error you mentioned, but I have made the change and reduced the code area to the following:

Set objNameSpace = objOutlook.GetNamespace("MAPI")

folderName = "iCloud"
Set foundFolder = FindInFolders(objOutlook.Session.Folders, folderName)

If Not foundFolder Is Nothing Then
Set objOutlook.ActiveExplorer.CurrentFolder = foundFolder
Set objCalendarItems = objOutlook.ActiveExplorer.CurrentFolder.Items
Else
MsgBox "Folder: " & folderName & " Not Found", vbInformation
End If

' At this point objCalendarItems should be pointing to the \\iCloud folder

Set curdb = CurrentDb

strWhereCond = "SELECT * FROM Entertainment WHERE ReferenceNo = " & Me!ReferenceNo
Set entertainmentRst = curdb.OpenRecordset(strWhereCond)

Do While Not entertainmentRst.EOF

strWhere = "[Reference] = " & Me!ReferenceNo & _
" AND [Line] = " & entertainmentRst!LineNo

' The program fails at this point as the property 'Reference' is not set

Set objAppointment = objCalendarItems.Find(strWhere)

Any additional insights would be appreciated

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close