Consulting

Results 1 to 12 of 12

Thread: Check Permissions To Add Outlook Appointment

  1. #1
    VBAX Newbie
    Joined
    Apr 2022
    Posts
    5
    Location

    Check Permissions To Add Outlook Appointment

    Hi All. I have VBA code which I downloaded years ago and has been running trouble-free. It's triggered from a form control in a spreadsheet which attempts to create an appointment in one of a number of staff member's Outlook calendars.

    Last week, something happened to permissions on all those calendars (result of some corporate changes) and the code was failing on an if condition. However, there were no errors being generated so it took me a long time to work out that it was a permissions error.

    Here's a snippet of the code.

     Dim objApp As Outlook.Application
     Dim objNS As Outlook.Namespace
     Dim objFolder As Outlook.MAPIFolder
     Dim objDummy As Outlook.MailItem
     Dim objRecip As Outlook.Recipient
     Dim objAppt As Outlook.AppointmentItem
     Dim objOutlook As Object
     
    '  A few lines of code here to set some variables for things like appointment time, duration etc..............
    
       If objRecip.Resolved Then  ' This has tested to make sure I have a valid recipient - I did have
            On Error Resume Next  ' Please note - I did try another option here which was a suggestion I saw and I changed this line to On Error GoTo 0 but that didn't produce anything??
            Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar) ' This sets a folder object to their calendar - this was working fine
            If Not objFolder Is Nothing Then
                Set objAppt = objFolder.Items.Add  ' this is then attempting to create an Appointment object.  The following If condition evaluated to false and therefore skipped the rest of the code that actually sets up all the appointment data
                If Not objAppt Is Nothing Then ' Need a better error check here to know that there was a permissions problem, not just skip to the Else/Endif
    Can someone suggest either:

    A way to test first to see if the user running the code does have permissions to create an appointment in the target calendar
    or
    A way to trap the error correctly and pop up an error message to inform the user that they don't have permission rather than the IF condition shown just evaluating to false.

    Many thanks in advance.

    David

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,635
    It seems the code does exactly that: discriminate between permitted and non-permitted users.

    So, if someone has no permission, then what ?

  3. #3
    VBAX Newbie
    Joined
    Apr 2022
    Posts
    5
    Location
    Quote Originally Posted by snb View Post
    It seems the code does exactly that: discriminate between permitted and non-permitted users.

    So, if someone has no permission, then what ?
    Thanks for the quick response. Yes, it's doing exactly what it should do and preventing them from creating an appointment if they don't have permissions. But I just want to be able to pop up a meaningful message that says "Sorry, you don't have permissions to create appointments in XXXXXX calendar".

    At the moment it just fails the IF condition and drops through. I could just put that message in at the ELSE point, but could there be other reasons why the attempt to add an appointment has failed? If so, I want to get back the actual error reason from Outlook so I can display a proper message.

    Hope that makes sense.

    Thanks, David

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,635
    It doesn't.
    Why shouds someone use a macro to do something (s)he is not entitled to ?
    What does this message help ? it's only irritating/frustrating.

  5. #5
    VBAX Newbie
    Joined
    Apr 2022
    Posts
    5
    Location
    Quote Originally Posted by snb View Post
    It doesn't.
    Why shouds someone use a macro to do something (s)he is not entitled to ?
    What does this message help ? it's only irritating/frustrating.
    Sorry, I thought I'd put enough info in the original post. The point is the users SHOULD have permissions to do this. Something changed on Friday as a result of some work by either our IT team or HR and accidentally removed the existing permissions that these users had.

    They're using a forms driven spreadsheet and they hit a button to confirm that they have gathered all the correct information. This then does various things including creating an appointment in the relevant engineer's calendar. This should have worked as they should have permissions. If they had seen an error message that said they didn't have permission they would have been able to inform me of the error and this would have saved me time in working out what had happened. We didn't expect the change in permissions so initially I wasn't looking at that as the problem.

    So, in summary, I would really like to be able to add a meaningful error message in case something like this happens again. Our users are not trying to do anything that they shouldn't be doing. The irritating/frustrating part was the lack of an error message that I could use to work out what was going wrong. So if there is a way of trapping this error or any other error that might be preventing the creation of the appointment that would be great as far as I'm concerned.

    Thanks, David

  6. #6
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,635
    I think you should contact IT in your company to restore permissions.

  7. #7
    VBAX Newbie
    Joined
    Apr 2022
    Posts
    5
    Location
    Quote Originally Posted by snb View Post
    I think you should contact IT in your company to restore permissions.
    Yeah, already done that - thank you for pointing out the obvious!!!! Everything is working fine now thanks. I'm simply asking if I can trap an error message if something like this happens again. It would have made it easier and quicker to find out that the permissions problem was the cause. Doesn't sound like you can help me with that so thanks.

  8. #8
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,635
    I can but I won't, since the obvious.

  9. #9
    VBAX Newbie
    Joined
    Apr 2022
    Posts
    5
    Location
    Quote Originally Posted by snb View Post
    I can but I won't, since the obvious.
    I really don't understand why you've taken such a hostile stance. I just came here looking for some help which is what I thought this forum was there for. I've obviously come to the wrong place or you're having a bad day. Sorry to have disturbed you.

  10. #10
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,635
    You'd better do some introspection why you assume 'hostility' in asking questions.
    If you fear questions you'd better stay inside.

  11. #11
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    You've already got an If clause that checks if it worked (i.e. an appointment was created) so you just need, as you said, to add a message to the Else part to indicate it didn't work, and the only real info about that you will have is from the error object, so you could do something like:

    If objAppt Is Nothing Then
       Msgbox "Failed to create appointment!" & vbcrlf & "Error: " & err.description
    else
    ' run your code
    End If
    Be as you wish to seem

  12. #12
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,158
    Location
    Quote Originally Posted by DSAJones View Post
    I really don't understand why you've taken such a hostile stance. I just came here looking for some help which is what I thought this forum was there for. I've obviously come to the wrong place or you're having a bad day. Sorry to have disturbed you.
    Hostile is a strong word - I would have used 'awkward' myself
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved

    Excel 365, Version 2401, Build 17231.20084

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •