none
VBA outlook appointment UserProperties RRS feed

  • Question

  • HI

    I have a small bit of vba code that accesses the details of an outlook appointment that has a outlook region.

    Sub sendOrder()

        Dim objOL As Outlook.Application
        Dim objSelection As Outlook.Selection
        Dim objItem As Object
        Dim accountname As String
        Dim Appointment As AppointmentItem
        Dim ref As String
        
        Set objOL = Outlook.Application
        Set objSelection = objOL.ActiveExplorer.Selection
                   
       For Each objItem In objSelection
           If objItem.Class = olAppointment Then
                Set Appointment = objItem
                    
                accountname = objItem.UserProperties.Item("forumaccount")
                ref = Appointment.UserProperties.Find("objectReference").Value
                                                         
           End If
        Next
             
    End Sub

    I click on the appointment and run my code.

    I'm finding that i inconsistently get a run time error 91. In my local variable window if i expand the Appointment declaration it takes  a bit little time to load and then im able to run my code again without errors.

    If anybody has any ideas that would be great.

    thanks

    Thursday, February 13, 2014 10:37 PM

All replies

  • Hello GeorgeMalkoun,

    Did you try to debug the code? What line of code generates the error?

    Please take a look at the Object variable or With block variable not set (Error 91) page in MSDN. It describes the error 91 in details.

    I'd recommend breaking the chain of property and method calls into separate lines. Thus, you will be able to find the problematic line of code. I have noticed the following line of code above:

       accountname = objItem.UserProperties.Item("forumaccount")

    The Item method of the UserProperties class returns an instance of the UserProperty class, not a string.

    ref = Appointment.UserProperties.Find("objectReference").Value
    Also, if the objectReference property does not exist you will get an error. That's why I suggested not using chained property or method calls.
    Friday, February 14, 2014 5:46 AM
  • You are assuming forumaccount and objectReference user properties are always present. You need to be a bit more defensive and guard against case when the properties are missing:

    set prop = Appointment.UserProperties.Find("objectReference")
    if Not (prop Is Nothing) Then
      res = prop.value
    End If


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Friday, February 14, 2014 5:47 AM
  • Hi Eugene

    thanks for replying, I'm slowly going mad.

    I have debugged and the code returns an error on the line

    accountname = objItem.UserProperties.Item("forumaccount")

    When i expand my objItem in my Locals view, I  find that the objItem takes a little bit of time before it opens, as if its loading its values. Once open i can stop my code and run through it again and it works returning the value in forumaccount. Is this a security issue?

    little bit more background

    1. Outlook appointment region created within outlook.

    2. Using visual Studio 2012, built all the code in vb.net for the buttons.

    3. installed the addin and all works good when creating an appointment

    4. Created vba code(as above) to manipulate appointments that have already been saved from the calendar view.

    5. Select appointment and run code. and that where i get into trouble.

    if it helps i can send you the addin and all the bits of vba. I'm using office 2010

    thank in advance

    Monday, February 17, 2014 5:15 AM
  • Thanks Dmitry

    your right i should handle my errors better, but i know that i have a value in the field and its something else that's causing the error

    Monday, February 17, 2014 5:17 AM
  • Can you be a bit more specific? What exactly is "something else that's causing the error"?

    What is your latest code? What is the error?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, March 3, 2014 6:20 AM
  • Hello George,

    Do you use Exchange server in the profile? If so, do you have the cached exchange mode turned on?

    Do you open appointments from a shared calendar?

    Monday, March 3, 2014 3:20 PM
  • Hi Dmitry

    I'm thinking its a security issue or a timing issue with talking to exchange.

    the error has no consistency to it .

    if you want i can send you the add-in to have a look.

    thanks

    Thursday, March 13, 2014 2:50 AM
  • Hi Eugene

    it is an exchange server. yes i did have exchange mode turned on, i have turned it off and still get the same issues.

    if you want i can send you the add-in to have a look.

    thanks for you help

    Thursday, March 13, 2014 2:55 AM
  • I really do not think so.

    What is you latest code?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, March 13, 2014 3:00 AM
  • Can i send you my addin?

    thanks

    Thursday, March 13, 2014 3:45 AM
  • Please post the relevant snippets of your code here. Let everybody benefit from the discussion.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, March 13, 2014 3:57 AM
  • Hi George,

    You can share your code here. The content of the forum thread may help other developers who will face with a similar issue.

    Friday, March 14, 2014 3:55 PM
  • Hi Eugeneand Dimitry

    I can put up my vba that triggers the problem, but my addin is a zip and i'm not sure the best way to get that up.

    Regards

    George

    Wednesday, March 19, 2014 1:04 AM
  • Please share any code which can help in reproducing the issue.
    Wednesday, March 19, 2014 6:54 AM