Win Form Outlook Scheduling App - Help with saving as different user/account

dsk96m

Well-known member
Joined
Jan 11, 2013
Messages
173
Programming Experience
1-3
I was tasked with creating a scheduling app for assets that we use. Each asset has an outlook calendar. At first, I knew it was impossible bc we only had Outlook 2007. We have since been upgraded to 2010. I know that one person cant make an appointment and it be edited by someone else. So I had my company create a new user (we use Microsoft Exchange server). I had people that will be using this application to add this new user/email account to their outlook.
My plan was the have the application create the calendar event using this global user so that others can edit it through the app as this global user.
So this is where I am. A co worker put in a request for an asset. It was added to the correct calendar with the meeting organizer as the global user I described above. The issue I am having now is that when I go into the app to approve the request (basically just changes the color of the outlook calendar item) it doesnt work. From what I can tell when my code tries to save the changes to the outlook appointment it is getting an error that I do not have the privileges. So it seems like my app is not creating the event as the non default outlook user.
each person will have their default outlook account (their company email), then they will also have this global user account. I cant seem to create the event with this global user account. What am i missing.
Below is my code for creating the event and for "Approving" the event:
VB.NET:
         Dim olApp As New Outlook.Application
        Dim olNameSpace As Outlook.NameSpace = olApp.GetNamespace("MAPI")
        Dim olPublicFolder As Outlook.MAPIFolder
        Dim olAppt As Outlook.AppointmentItem

        Me.Cursor = Cursors.WaitCursor
        olApp = CreateObject("Outlook.Application")
        olNameSpace.Logon("Bench Scheduler", "", False, False)

        olPublicFolder = olNameSpace.Folders("Public Folders - BenchScheduler@uuu.com")
        For i As Integer = 0 To calendarpath.Length - 1
            If calendarpath(i) <> "" And calendarpath(i) <> "Public Folders" Then
                olPublicFolder = olPublicFolder.Folders.Item(calendarpath(i))
            End If
        Next

        olAppt = olPublicFolder.Items.Add("IPM.Appointment")
        olAppt.MeetingStatus = Outlook.OlMeetingStatus.olMeeting

        With olAppt
            .Subject = ("Requested (ID-" & br.request_id & "): " & br.project_name & "-" & Me.typeCombobox.SelectedItem(1))
            .Location = br.bench_name
            If IsDBNull(br.setups_string) Then
                bodytext = br.comments & vbCrLf & vbCrLf & "Bench Setups Requested:" & vbCrLf & br.setups_string.ToString
            Else
                bodytext = br.comments
            End If
            .Body = bodytext
            .Start = CDate(br.requestdate & " " & br.start_time)
            .ReminderMinutesBeforeStart = 15
            .ReminderSet = True
            .Duration = DateDiff(DateInterval.Minute, (br.requestdate & " " & br.start_time), (br.requestdate & " " & br.end_time))

            For Each recip As String In br.requiredusers_email
                .Recipients.Add(recip)
                .Recipients(recip).Type = Outlook.OlMeetingRecipientType.olRequired
            Next

            For Each recip As String In br.optionalusers_email
                .Recipients.Add(recip)
                .Recipients(recip).Type = Outlook.OlMeetingRecipientType.olOptional
            Next

            .Recipients.ResolveAll()
            .Categories = "Yellow Category"
            .ResponseRequested = True
            .BusyStatus = Outlook.OlBusyStatus.olBusy
            .Save()
        End With

        entryid = olAppt.EntryID
        olAppt.Save()
Approval code:
VB.NET:
         Dim olApp As New Outlook.Application
        Dim olNameSpace As Outlook.NameSpace = olApp.GetNamespace("MAPI")
        Dim olPublicFolder As Outlook.MAPIFolder
        Dim olAppt As Outlook.AppointmentItem

        olApp = CreateObject("Outlook.Application")
        olNameSpace.Logon("Bench Scheduler", "", False, False)

        olPublicFolder = olNameSpace.Folders("Public Folders - BenchScheduler@uuu.com")
        For i As Integer = 0 To calendarpath.Length - 1
            If calendarpath(i) <> "" And calendarpath(i) <> "Public Folders" Then
                olPublicFolder = olPublicFolder.Folders.Item(calendarpath(i))
            End If
        Next
        On Error Resume Next

        Dim oItems As Outlook.Items = olPublicFolder.Items

        For i As Integer = 1 To oItems.Count
            'Test to make sure item is a mail item and not a meeting request.
            If InStr(oItems.Item(i).subject.ToString, "ID-" & requestid) > 0 Then
                olAppt = oItems(i)
                Exit For
            End If
        Next

        With olAppt
            .Subject = Replace(.Subject, "Requested", "Approved")
            .Categories = "Green Category"
            .Save()
            .Send()
        End With

What am I missing? This is killing me. This is my last obstacle before being done with this application. Any help would be greatly appreciated.
 
Back
Top