none
Using vba classes to tranfer Outlook contact.userproperties data using Application.ActiveInspector RRS feed

  • Question

  • Hello,

    this is a problem that I am having trying to copy user data from Outlookcontact items by way of a VBA class.I get the data that I want to display input toMsgbox alright, but to get Herrera when I try to assign to a variable. Here is the code: –

    Private moApp As Variant
    Private moInspector As Outlook.Inspector
    Private moCase As Variant
    Private moClaimants As Object

     
     
    Private Sub Class_Initialize()
    Set moInspector = Application.ActiveInspector

    Set moCase = moInspector.CurrentItem
    Set moClaimants = moCase.UserProperties("Claimants")

    End Sub

    Public Property Get caseItem() As Variant
    caseItem = Inspector.CurrentItem
    End Property

    Property Get claimants() As String
    claimants = moClaimants

    End Property.

    and a subroutine to run the code: –

    Sub Tester()

    Dim Item As Object
    Dim Item2 As Object

    Set Item = New LawCase
    MsgBox Item.claimants

    Set Item2 = Item.claimants

    End Sub

    Thanks,

    David Hyde






    Friday, June 8, 2012 7:44 PM

Answers

  • What line fires an error?
     
    Does that UserProperty actually exist on then item? Your code assumes it does, it would be a null object if it doesn't exist:
     
    Set moClaimants = moCase.UserProperties("Claimants")

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "DavidHyde" <=?utf-8?B?RGF2aWRIeWRl?=> wrote in message news:819d853d-4c40-4ffd-b053-ab58bcda833a...

    Hello,

    this is a problem that I am having trying to copy user data from Outlookcontact items by way of a VBA class.I get the data that I want to display input toMsgbox alright, but to get Herrera when I try to assign to a variable. Here is the code: –

    Private moApp As Variant
    Private moInspector As Outlook.Inspector
    Private moCase As Variant
    Private moClaimants As Object

     
     
    Private Sub Class_Initialize()
    Set moInspector = Application.ActiveInspector

    Set moCase = moInspector.CurrentItem
    Set moClaimants = moCase.UserProperties("Claimants")

    End Sub

    Public Property Get caseItem() As Variant
    caseItem = Inspector.CurrentItem
    End Property

    Property Get claimants() As String
    claimants = moClaimants

    End Property.

    and a subroutine to run the code: –

    Sub Tester()

    Dim Item As Object
    Dim Item2 As Object

    Set Item = New LawCase
    MsgBox Item.claimants

    Set Item2 = Item.claimants

    End Sub

    Thanks,

    David Hyde







    Ken Slovak MVP - Outlook
    Monday, June 11, 2012 3:18 PM
    Moderator

All replies

  • What line fires an error?
     
    Does that UserProperty actually exist on then item? Your code assumes it does, it would be a null object if it doesn't exist:
     
    Set moClaimants = moCase.UserProperties("Claimants")

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "DavidHyde" <=?utf-8?B?RGF2aWRIeWRl?=> wrote in message news:819d853d-4c40-4ffd-b053-ab58bcda833a...

    Hello,

    this is a problem that I am having trying to copy user data from Outlookcontact items by way of a VBA class.I get the data that I want to display input toMsgbox alright, but to get Herrera when I try to assign to a variable. Here is the code: –

    Private moApp As Variant
    Private moInspector As Outlook.Inspector
    Private moCase As Variant
    Private moClaimants As Object

     
     
    Private Sub Class_Initialize()
    Set moInspector = Application.ActiveInspector

    Set moCase = moInspector.CurrentItem
    Set moClaimants = moCase.UserProperties("Claimants")

    End Sub

    Public Property Get caseItem() As Variant
    caseItem = Inspector.CurrentItem
    End Property

    Property Get claimants() As String
    claimants = moClaimants

    End Property.

    and a subroutine to run the code: –

    Sub Tester()

    Dim Item As Object
    Dim Item2 As Object

    Set Item = New LawCase
    MsgBox Item.claimants

    Set Item2 = Item.claimants

    End Sub

    Thanks,

    David Hyde







    Ken Slovak MVP - Outlook
    Monday, June 11, 2012 3:18 PM
    Moderator
  • Dear Ken Slovak,

    Thank you for that. I have amended my code to use the ".UserProperties.Find("Claimants")", which gives a correct result.

    I still don't understand why ".UserProperties.UserProperties ("Claimants")", " returns the right answer to Mgbox but wasn't accepted as the return value from the function. I can live without knowing!

    Regards,

    David Hyde
    Tuesday, June 12, 2012 11:22 AM
  • David,

    Please create new thread for new question.

    thanks,


    Forrest Guo | MSDN Community Support | Feedback to manager

    Friday, June 22, 2012 3:26 AM
    Moderator