Consulting

Results 1 to 14 of 14

Thread: Solved: question about "UserProperties"

  1. #1
    VBAX Regular
    Joined
    Mar 2005
    Location
    Latvia; Germany
    Posts
    19
    Location

    Question Solved: question about "UserProperties"

    Hi!
    I have user defined field "Number" in one of my folders.
    Data Type for this field - "Integer"
    I trying to change it by using UserProperties:

    >Dim myItem As MailItem
    >
    > myItem.UserProperties.Add "Number", olNumber
    > myItem.UserProperties("Number") = "111"

    But recive error
    "A custom field with this name, but different Data Type alredy exists. Enter a different name"

    I try to write -
    myItem.UserProperties.Add "Number", olNumber
    but "Data type is not supported"

    So, somebody can help me ?

    Regards!

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Hi again,
    This is happening because you're trying to put a number into a text property.
    If you want to use the same proerty name ("Number") you'll have to delete it first then add it a a olNumber type.
    I don't have outlook available right now but it's something like this:
    myItem.UserProperties.Remove("Number")
    myItem.UserProperties.Add "Number", olNumber

    You might have to use the Find method on the Item first to check its name, "Number", get its Index and Remove referring to the index:
    myItem.UserProperties.Remove(index)

    Hope that's helped
    K :-)

  3. #3
    VBAX Regular
    Joined
    Mar 2005
    Location
    Latvia; Germany
    Posts
    19
    Location
    Hi Killian!

    I alredy try to remove it at first but recive error "Type mismatch"
    But IMHO problem not in this!

    Because for other fields with other types I don't need to do it. It working well.

    Field "Number" alredy exists in Outlook & have Type "Integer"
    But User Property have only:
    OlUserPropertyType
    olOutlookInternal = 0
    olText = 1
    olNumber = 3
    olDateTime = 5
    olYesNo = 6
    olDuration = 7
    olKeywords = 11
    olPercent = 12
    olCurrency = 14
    olFormula = 18
    olCombination = 19

    So, number not acceptible! I need find the way to use Integer in UserProperty.
    If it posible ?

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi,

    Could this be as simple as it looks?

    You're using "111" to fill the value property like Killian says you can't asign a string to an Integer property. (Or you should convert it with Val() or CInt())

    In you're case you can change this line: [VBA]myItem.UserProperties("Number").Value = "111"

    'with:

    myItem.UserProperties("Number").Value = 111[/VBA]

    A simple test procedure that adds a new contact with property:[VBA]
    Sub UserProp()
    Dim oApp As New Outlook.Application
    Dim oItem As Outlook.ContactItem
    Set oItem = oApp.CreateItem(olContactItem)
    With oItem
    .UserProperties.Add "aNumber", olNumber
    .UserProperties("aNumber").Value = 111

    MsgBox .UserProperties("aNumber").Value
    .Display
    End With
    End Sub
    [/VBA]
    Enjoy!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  5. #5
    VBAX Regular
    Joined
    Mar 2005
    Location
    Latvia; Germany
    Posts
    19
    Location
    Hi!

    You don't understand me. Line that I show before it's just example. But wharever :
    >Dim myItem As MailItem
    >
    > myItem.UserProperties.Add "Number", olNumber
    > myItem.UserProperties("Number") = "111"

    I recive error when I try to change filed type (Not when define value for it)!
    It's the problem!
    I have a lot(more then 1000) of fields in Outlook with Type Integer!
    But I can't Define for UserProperty Integer Type! Only "Number"

    2 Killian
    I think the best way is, how you alredy said to remove item, then make new!
    But I recive error "Type mismatch" at this line

    >myItem.UserProperties.Remove "Number"

    What it can be ?

    Regards to all.

  6. #6
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Yeah, these UserProperties in Outlook are a little strange...
    You must refer to them by index, not by name. Therefore the best way to do this is loop through the collection and test for what you want, then do something with it.
    I just tested this routine and it seems to work fine. It will go through each of the selected mails and if it has the "Number" property, remove it and add a new one of type olNumber[VBA]Sub ReplaceAll()

    Dim olItem As MailItem
    Dim i As Long

    For Each olItem In Application.ActiveExplorer.Selection
    For i = 1 To olItem.UserProperties.Count
    If olItem.UserProperties.Item(i).Name = "Number" Then
    olItem.UserProperties.Remove (i)
    olItem.UserProperties.Add "Number", olNumber
    olItem.UserProperties.Item(i).Value = 111
    End If
    Next
    Next

    End Sub[/VBA]
    K :-)

  7. #7
    VBAX Regular
    Joined
    Mar 2005
    Location
    Latvia; Germany
    Posts
    19
    Location
    Thanx Killian!

    But the same error!
    Field with this name, but different data type alredy exists!

    >olItem.UserProperties.Remove (i)
    Actually not delete the field, the same with:
    > olItem.UserProperties.Item(i).Delete

    I think the best way to make a new field with diferent name and "Number" Type and ignore old one.

    Regards.

  8. #8
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    I think the best way to make a new field with diferent name and "Number" Type and ignore old one.
    Probably true...
    Although, I don't really understand why it fail on the remove line - the data type isn't important.
    K :-)

  9. #9
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by separator
    Hi!

    You don't understand me. Line that I show before it's just example. But wharever :
    Hi,

    Well I think I did understand you're questione but I cannot reproduce you're errors on my machine...
    >Dim myItem As MailItem
    >
    > myItem.UserProperties.Add "Number", olNumber
    > myItem.UserProperties("Number") = "111"

    I recive error when I try to change filed type (Not when define value for it)!
    It's the problem!
    I have a lot(more then 1000) of fields in Outlook with Type Integer!
    But I can't Define for UserProperty Integer Type! Only "Number"
    To my knowledge olNumber is an Integer constant!

    And on my machine it does accept Integers..(For that matter it even accepts Strings...so seams to be off variant type??)

    Tested it against an integer like by converting string to integer:[VBA]
    .UserProperties("aNumber").Value = CInt("111")[/VBA]

    Like Killian I have some trouble understanding what's causing this problem in you're enviroment.

    The ReplaceAll sub runs fine over here ... don't understand this!

    No errors what so ever if I try to add the property twice in one sub:[VBA]
    Sub UserProp2()
    Dim oApp As New Outlook.Application
    Dim oItem As Outlook.MailItem
    Set oItem = oApp.CreateItem(olMailItem)
    With oItem
    .UserProperties.Add "Number", olNumber
    .UserProperties("Number").Value = 111

    .UserProperties.Add "Number", olNumber
    .UserProperties("Number").Value = 111

    MsgBox .UserProperties("Number").Value
    .Display
    End With
    End Sub
    [/VBA]
    Perhaps you can attach you're whole procedure perhaps there is something else in there that's causing this problem?

    Enjoy!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  10. #10
    VBAX Regular
    Joined
    Mar 2005
    Location
    Latvia; Germany
    Posts
    19
    Location
    Yes I can. Here it is:

    Sub SelectedChange(statStatus, statOwn, statCustomer, statTechnology, statKeyWords, statTargetDate)

    Public StatNumber As Integer
    Public Change_Number As Boolean
    Public Change_Status As Boolean
    Public Change_Own As Boolean

    Dim myOlApp As New Outlook.Application
    Dim myOlExp As Outlook.Explorer
    Dim myOlSel As Outlook.Selection
    Dim MsgTxt As String
    Dim myItem As MailItem

    Set myOlExp = myOlApp.ActiveExplorer
    Set myOlSel = myOlExp.Selection
    For Each myItem In myOlSel
    If Change_RTN = True Then
    myItem.UserProperties.Add("Number", olText).Value = statNumber
    myItem.Save
    End If
    If Change_Status = True Then
    myItem.UserProperties.Add("Status", olText).Value = statStatus
    myItem.Save
    End If
    If Change_Own = True Then
    myItem.UserProperties.Add("Own", olText).Value = statOwn
    myItem.Save
    End If
    Next

    End Sub

  11. #11
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi,

    Little time today but I'll review tommorow..

    First you're code has errors in them. Put Option Explicit on top of you're program code en run you're code...It will not be executed!

    Main reason is because you use "Public" variables inside you're Subprocedure. This is not allowed..Put them on top right under the Option Explicit.

    Also the sub has 6 parameters and you're only using 2 off them in you're code..why is that? (Seems redundant to me)

    Further more the parameters aren't dimensioned e.g.: statStatus As String, statOwn As string, etc...

    So there all Variants right now and that makes for slow code execution.

    Take a look at it and tommorow I'll test you're sub..

    Enjoy!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  12. #12
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi,

    I've been getting the same error executing you're code on the emails found in the sellection.

    Still I'm not able to fully understand why this error occurs.

    What have I done:
    * Run a sub that prints all the userProperties on the selected emails in the Inbox. (This to make shure that there wasn't any before I run you're sub on it)

    * So at that point I knew there was no Number propertie in it. (That I could see that is)

    * Running you're code on it I received the Ghost error. The strange thing is that this only happens to allready existing emails. If you create a new one and give it the Number property then there's no problem what so ever.

    * The other thing is that it only happens with the property called: "Number" if you call in "aNumber" in you're procedure..all runs well!!!

    That fact only makes me believe that "Number" is some kind off "Reserved" Word in Outlook that Outlook needs for it's one. (Every application has a bunch of reserved words that you're not supposed to use)

    So If you just use a different name for you're property other then "Number" everything runs well. (at least it does over here)

    Enjoy!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  13. #13
    VBAX Regular
    Joined
    Mar 2005
    Location
    Latvia; Germany
    Posts
    19
    Location
    Thanx to all
    Now just using different name

  14. #14
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi,

    Glad you've got it working now...you're welcome!
    ps..could you mark you're thread solved?
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

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