Access appointments to Exchange Server problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AndyWal6
    New Member
    • Mar 2007
    • 14

    Access appointments to Exchange Server problem

    Hi All!
    I have constructed the Function below to handle sending appointments to Outlook calendars on Local machine or Exchange Server depending on my clients settings.
    As you can see olExchFolder is either yes or no and use the routines as noted.
    The code I have gleaned from many different sources and cobbled together.

    The first part works perfectly sending to local folder. olExchFolder = False
    But the second part of the If statement olExchFolder = True raises the error 440 Outlook does not recognize one or more names.

    Can anyone see an obvious fault in the code after the 'Else' statement that is stopping it working or am I not addressing the Outlook folder correctly?
    Any help would be much appreciated.

    Andy.

    Code:
    Public Function SendAppointmentToOutlook( _
            olExchFolder As Boolean, _
            olCalendarName As String, _
            olStartDate As String, _
            olEndDate As String, _
            olLocation As String, _
            olSubject As String, _
            olBody As String, _
            Optional olDuration As Long = 0, _
            Optional olAllDayEvent As Boolean = True, _
            Optional olReminderMinutes As Long = 90, _
            Optional olReminderSet As Boolean = False)
            
            Dim outobj As Object   ' *The Outlook.Application
            Dim outappt As Object  ' *The Outlook.AppointmentItem
            Dim olFolder As Object ' *The Required Folder/Calendar
            Dim Namespace As Object
            Dim objOutlook As Object
            Dim Recipient As Outlook.Recipient
                    
    If olExchFolder = False Then ' *Calendars are sub Calendars in My Calendars Folder on Local machine
            
            Set outobj = CreateObject("outlook.application")
            Set olFolder = outobj.GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar).Parent.Folders(olCalendarName)
            'Set olFolder = outobj.GetNamespace("MAPI").pickFolder  ** Calls MAPI Dialog to choose Folder
            Set outappt = olFolder.Items.Add
            
    Else    ' *Calendars are in Exchange Folder
    
            Set objOutlook = New Outlook.Application
            Set Namespace = objOutlook.GetNamespace("MAPI")
            Set Recipient = Namespace.CreateRecipient(olCalendarName)
            Set outappt = Namespace.GetSharedDefaultFolder(Recipient, olFolderCalendar).Items.Add
    End If
    
            With outappt
                .Start = olStartDate
                .End = olEndDate
                .Duration = olDuration
                .AllDayEvent = olAllDayEvent
                .Location = olLocation
                .Subject = olSubject
                .Body = olBody
                .ReminderMinutesBeforeStart = olReminderMinutes
                .ReminderSet = olReminderSet
                .Save
            End With
    
             ' *Release the Outlook object variables.
             Set outobj = Nothing
             Set outappt = Nothing
             Set olFolder = Nothing
             Set Namespace = Nothing
             Set Recipient = Nothing
             Set objOutlook = Nothing
             
    End Function
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3662

    #2
    Which line of code is inducing the error? That might help us focus our attention....

    Comment

    • twinnyfo
      Recognized Expert Moderator Specialist
      • Nov 2011
      • 3662

      #3
      Oddly enough, I just put this code into my VB Editor and it ran without a hitch....

      I'm wondering now where the disconnect might be....

      Comment

      • twinnyfo
        Recognized Expert Moderator Specialist
        • Nov 2011
        • 3662

        #4
        I just tried it again with another user's name.... I think the problem could most have to do with permissions.

        I have some code that sends out an appointment, but it doesn't insert it directly into the calendar, but sends it out as you would a normal appointment request. The only problem is that the current user is the one who is the requester, whereas your code puts it out there discreetly.

        Are you interested in the alternate option?

        Comment

        • AndyWal6
          New Member
          • Mar 2007
          • 14

          #5
          Thank you twinnyfo
          If I set a break point at the line:
          Set outappt = Namespace.GetSh aredDefaultFold er(Recipient, olFolderCalenda r).Items.Add
          and check values of the other parts by hovering.
          outobj = "Outlook"
          NameSpace = "Mapi"
          Recipient = "TestCal" (the name of the shared calendar)
          olFolderCalenda r = 9
          outappt = "Nothing"

          I get Error 440 Outlook does not recognize one or more names.

          Comment

          • AndyWal6
            New Member
            • Mar 2007
            • 14

            #6
            The Calendars are all Fully shared calenders with read/write permissions and currently in use. The first part of the code works great with multiple calendars which are sub folders of parent folder 'My Calendars'
            The second part is supposed to work in the same way with shared folders on Exchange Server. But I have this hic-up.
            When it works the Administrator will be able to make appointments with customers, log them in Access and send them out to the relevant salespersons calendar.
            Thanks for the offer of option 2.

            Comment

            • twinnyfo
              Recognized Expert Moderator Specialist
              • Nov 2011
              • 3662

              #7
              To be honest, I love you concept and hav ebeen wanting to know how to do it, but I can't in our environment because of security.

              Is "TestCal" the full name of the account? Does it have a separate e-mail address? You could try the e-mail address as that worked for me when I used my own account.

              Comment

              • AndyWal6
                New Member
                • Mar 2007
                • 14

                #8
                Thank you for your interest twinnyfo.
                The function as written works perfectly.
                The problem was in the form where I inserted the calendar name.
                Feel free to use the function in any way you like.

                Comment

                Working...