Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    NISMOJim is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2010
    Posts
    273
    I added this code before setting up a break point just below. Getting the name of the objects that the code picks up sounds like a great idea.

    Dim oApp As Object
    Dim oCalendar As Outlook.MAPIFolder
    Dim oNameSpace As Outlook.NameSpace
    Dim oAppt As Outlook.AppointmentItem
    Dim oAcct As Outlook.Recipient
    Dim ApptNotes As String
    Dim strName As String
    Dim calName As String


    'On Error GoTo Err_Exit

    calName = "ATCG8S1"
    Set oApp = CreateObject("Outlook.Application.16")
    Set oNameSpace = oApp.GetNamespace("Mapi")
    Set oAcct = oNameSpace.CreateRecipient(calName)

    Dim obj As Object
    For Each obj In oNameSpace.GetSharedDefaultFolder(oAcct, olFolderCalendar)
    Debug.Print obj.Name
    Next


    Now I'm getting the same error (Outlook does not recognize one or more names.), this time on the "For Each obj In oNameSpace.GetSharedDefaultFolder(oAcct, olFolderCalendar)" line.
    Is olFolderCalendar a generic code term, or is the code looking for a folder in Outlook named "FolderCalendar" that maybe doesn't exist? Or does it have something to do with the GetSharedDefaultFolder name? Could the calendar default to a different folder?

  2. #17
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Maybe:

    Set oCalendar = oNameSpace.GetDefaultFolder(olFolderCalendar).Fold ers("ATCG8S1")

    Code recognizes a sub calendar but I have permission issues and can't edit. I never created these calendars (US Holidays, Birthdays), I think they are default with Outlook. I tried creating a new calendar but code doesn't see it. Annoying.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #18
    hunterpaw is offline Novice
    Windows 8 Access 2016
    Join Date
    Feb 2019
    Posts
    1
    Quote Originally Posted by NISMOJim View Post
    Set oAcct = oNameSpace.CreateRecipient(calName)
    This line will not create an Outlook Appointment nor will it set a reference to a Calendar.

    You need to set a reference to the Calendar. The easiest way to do this, since you are not experienced with the code, is to use the Outlook PickFolder Dialog with this line of code:
    Set oCalendar = oNameSpace.PickFolder

    This will open the Outlook PickFolder Dialog where you can select the Calendar.

    Then you can create a new Outlook Appointment in that Calendar like this:
    Set oAppt = oCalendar.Items.Add

  4. #19
    NISMOJim is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2010
    Posts
    273
    Ok, something different happened. We're getting very close! Here is the code I have now...

    Private Sub cmdReserve_Click()


    Dim oApp As Object
    Dim oCalendar As Outlook.MAPIFolder
    Dim oNameSpace As Outlook.NameSpace
    Dim oAppt As Outlook.AppointmentItem
    Dim oAcct As Outlook.Recipient
    Dim ApptNotes As String
    Dim strName As String
    Dim calName As String

    calName = "ATCG8S1"


    Set oApp = CreateObject("Outlook.Application.16")
    Set oNameSpace = oApp.GetNamespace("Mapi")
    Set oAcct = oNameSpace.CreateRecipient(calName)
    Set oCalendar = oNameSpace.PickFolder
    Set oAppt = oCalendar.Items.Add

    'Save Appointment
    With oAppt
    .Subject = Me!txtUser & " " & Me!txtGrp
    .Start = Format(Me.txtStartDate, "Short Date") & " " & Format(Me.txtStartTime, "Short Time")
    .End = Format(Me.txtEndDate, "Short Date") & " " & Format(Me.txtEndTime, "Short Time")
    .ReminderSet = False
    .AllDayEvent = AllDay
    .Save
    .Close (olSave)
    End With
    MsgBox "Appointment Added!", vbInformation

    'Release the Outlook object variable
    Set oCalendar = Nothing
    Set oNameSpace = Nothing
    Set oApp = Nothing


    Err_Exit:
    Set oCalendar = Nothing
    Set oNameSpace = Nothing
    Set oApp = Nothing
    Exit Sub

    End Sub

    When I click the command button, I get a popup window that says Select Folder. My options look the same as my email options (inbox, Deleted Items, Junk Mail, etc.). The calendars are also there, but I still would like the code to select the correct calendar. When I select it manually, the appointment is added to the calendar I select, which is a HUGE step forward. As a reminder, there will be a calendar for each building, so I don't want the user to be able to select the wrong one, all of this part should happen behind the scenes. The only thing the user will see is the message box that says "Appointment Added". Can we drill down deeper to tell the code which calendar to add the appointment to?

  5. #20
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Please post lengthy code within CODE tags to retain indentation and readability. Also, forum will drop some characters when not between CODE tags.

    I have read something about getting Outlook folder with its StoreID and EntryID https://docs.microsoft.com/en-us/off...s-and-storeids

    Found some code that can loop through folders and read those properties https://stackoverflow.com/questions/...der-in-outlook

    Loop through folders collection and in a conditional statement could check if folder Name property matches a given name, then set to that folder.

    Code to test listing Outlook folders and reading properties, condensed from above link.

    Code:
    Sub ListFolders()
    Dim olApp As Outlook.Application
    Dim olNs As Outlook.Namespace
    Dim olparentfolder As Outlook.Folder
    Dim olFolder As Outlook.Folder
    On Error Resume Next
    Set olApp = GetObject(, "Outlook.Application")
    On Error GoTo 0
    If olApp Is Nothing Then
        Set olApp = CreateObject("Outlook.Application")
    End If
    Set olNs = olApp.GetNamespace("MAPI")
    Set olparentfolder = olNs.GetDefaultFolder(olFolderCalendar)
    Debug.Print "Parent: " & olparentfolder.FolderPath & " StoreID: " & olparentfolder.StoreID
    If (olparentfolder.Folders.Count > 0) Then
        For Each olFolder In olparentfolder.Folders
            Debug.Print "Subfolder: " & olFolder.FolderPath
        Next
    End If
    ExitRoutine:
        Set olparentfolder = Nothing
        Set olNs = Nothing
        Set olApp = Nothing
    End Sub
    Understand that one reason it's difficult to manipulate Outlook 'folders' is because they aren't really folders. All Outlook data is stored in a .pst or .ost file, including the 'folder' structure.
    https://lookeen.com/blog/where-does-...k-store-emails
    https://www.outlook-tips.net/beginne...outlook-files/
    Last edited by June7; 02-25-2019 at 12:09 AM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #21
    NISMOJim is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2010
    Posts
    273
    I ran the code you posted, and got the Parent folder path & store ID, along with the calendar subfolder path, which is the one I want the code to work with.

    Subfolder: \\Lov**@***.****.COM\Calendar\ATCG8S1

    Now is there a way to plug this path into the code somewhere to tell the code where to make the appointment?
    I apologize for my ignorance, but thank you for hanging in there with me.

  7. #22
    NISMOJim is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2010
    Posts
    273
    Here is the line of code that seems to be finally working...

    Set oCalendar = oNameSpace.GetDefaultFolder(olFolderCalendar).Fold ers("ATCG8S1")

    Thank you all for your help and direction.

  8. #23
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Those elements might not be necessary after all.

    Within the loop, try:
    Code:
    If olFolder.Name = strName Then
        Set olAppt = olFolder.Items.Add(olAppointmentItem)
        With olAppt
            …
        End With
        Exit For
    End If
    Now I see your post - and the simplest works after all! Glad to help.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Adding an appointment to Outlook shared calendar
    By simon123 in forum Programming
    Replies: 1
    Last Post: 08-03-2018, 11:14 AM
  2. Replies: 4
    Last Post: 09-24-2014, 09:26 AM
  3. Access - Outlook Appointment shared calendar
    By Guerra67 in forum Access
    Replies: 1
    Last Post: 09-21-2014, 07:26 PM
  4. Replies: 1
    Last Post: 05-31-2013, 02:04 AM
  5. Replies: 1
    Last Post: 03-21-2013, 11:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums