Code to update Existing Contact Information 
Author Message
 Code to update Existing Contact Information

It actually looks like you're making a lot of progress. 1 & 2 should be working fine.

#3a is the step to tackle next -- looking for a matching item. This is what you have so far:

      Dim FolioNumber As Object
    <snip>
    Set FolioNumber = objItemUpdateContact.User1
    Set objItemExistingContact = objItemsExistingContacts.Items.Restrict(FolioNumber)

There are 4 basic problems with this:

1) ContactItem.User1 is a string property, not an object property. (You can look this kind of thing up in the object browser.)

2) You use Set only with object variables, not with string variables.

3) If you're looking for just one matching item, Find is more efficient than Restrict.

4) Your Restrict string only tells Outlook what value to look for. It doesn't specify where to look for it. The Find/Restrict string must always be an expression that includes a) the field where you want to look, b) an operator, such as = or >, and c) the value you want to look for. This is covered in great detail in TYO2KP on pp. 261-3. Note that a string value will need surrounding quotation marks.

Best practice is to build the Find/Restrict string separately. This makes it easy to use a MsgBox or Debug.Print statement to test the value.

When you need to include the value of a string variable, you can make the code more readable by using the simple Quote() function found on page 133 to add the quotation marks.

Keeping those basics in mind, your code would look something like:

    Dim FolioNumber As String
    Dim strFind as String
    <snip>    
    FolioNumber = objItemUpdateContact.User1
    strFind = "[User1] = " & Quote(FolioNumber)
    Set objItemExistingContact = objItemsExistingContacts.Restrict(strFind)

Let's see if that gets you to the next step

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.*-*-*.com/
Author of
     Microsoft Outlook Programming: Jumpstart
     for Administrators, Power Users, and Developers
      http://www.*-*-*.com/

Quote:

> My previous post was replied to by Sue Mosher indicating I
> would need custom code to do this:  This is my sad
> attempt.  

> I've been working with the TYO2000IN24HRS and am quite
> obviously still confused:  I would like the code below to
> 1)Choose a Folder with updated contact information 2)
> Choose a Folder with existing contact information 3) For
> each item in '1' a)check if there is a contact in '2' with
> the same value for a user property b)if there isn't, move
> the item from '1' to '2' c) if there is, copy the value of
> a 2nd user property in '1' to the corresponding field
> in '2'.  And now that I think about it, for b) the code
> will also have to copy the 2nd user property to the
> corresponding field once the contact has been moved to '2'.

> Any suggestions on how to make the code more readable will
> be greatly appreciated as well.

> And since you are probably laughing by now, consider the
> tears of laughter I have brought to your eyes a little
> gift from me to say thank you for the help I'm hoping to
> receive.

> And one more thing - I am starting to re-read the book
> tonight and will spend much more time on each topic,
> making sure I understand it before I move to the next
> topic.

> Sub UpdateUserPropertyOrCopyInNewContact()

>   Dim objApp As Application
>   Dim objNS As NameSpace
>   Dim objExistingContactsFolder As MAPIFolder
>   Dim objUpdateContactsFolder As MAPIFolder
>   Dim objItemsUpdateContacts As Items
>   Dim objItemsExistingContacts As Items
>   Dim objItemUpdateContact As Object
>   Dim objItemExistingContact As Object
>   Dim FolioNumber As Object

>   Set objApp = CreateObject("Outlook.Application")
>   Set objNS = objApp.GetNamespace("MAPI")

>   Set objUpdateContactsFolder = objNS.PickFolder()
>   Set objExistingContactsFolder = objNS.PickFolder()

>   Set objItemsUpdateContacts =
> objUpdateContactsFolder.Items
>   Set objItemsExistingContacts =
> objExistingContactsFolder.Items

>     For Each objItemUpdateContact In objItemsUpdateContacts
>         Set FolioNumber = objItemUpdateContact.User1
>         Set objItemExistingContact =
> objItemsExistingContacts.Items.Restrict(FolioNumber)
>             If objItemExistingContact Is Nothing Then
>                 objItemUpdateContact.Move
> objExistingContactsFolder
>             Else: objItemExistingContact.UserProperties
> ("Total Assets") = objItemUpdateContact.User2
>             End If
>     Next

>   Set objApp = Nothing
>   Set objNS = Nothing
>   Set objExistingContactsFolder = Nothing
>   Set objUpdateContactsFolder = Nothing
>   Set objItemsUpdateContacts = Nothing
>   Set objItemsExistingContacts = Nothing
>   Set objItemUpdateContact = Nothing
>   Set objItemExistingContact = Nothing
>   Set FolioNumber = Nothing

> End Sub



Sat, 30 Apr 2005 04:48:33 GMT  
 Code to update Existing Contact Information
My previous post was replied to by Sue Mosher indicating I
would need custom code to do this:  This is my sad
attempt.  

I've been working with the TYO2000IN24HRS and am quite
obviously still confused:  I would like the code below to
1)Choose a Folder with updated contact information 2)
Choose a Folder with existing contact information 3) For
each item in '1' a)check if there is a contact in '2' with
the same value for a user property b)if there isn't, move
the item from '1' to '2' c) if there is, copy the value of
a 2nd user property in '1' to the corresponding field
in '2'.  And now that I think about it, for b) the code
will also have to copy the 2nd user property to the
corresponding field once the contact has been moved to '2'.

Any suggestions on how to make the code more readable will
be greatly appreciated as well.

And since you are probably laughing by now, consider the
tears of laughter I have brought to your eyes a little
gift from me to say thank you for the help I'm hoping to
receive.

And one more thing - I am starting to re-read the book
tonight and will spend much more time on each topic,
making sure I understand it before I move to the next
topic.

Sub UpdateUserPropertyOrCopyInNewContact()

  Dim objApp As Application
  Dim objNS As NameSpace
  Dim objExistingContactsFolder As MAPIFolder
  Dim objUpdateContactsFolder As MAPIFolder
  Dim objItemsUpdateContacts As Items
  Dim objItemsExistingContacts As Items
  Dim objItemUpdateContact As Object
  Dim objItemExistingContact As Object
  Dim FolioNumber As Object

  Set objApp = CreateObject("Outlook.Application")
  Set objNS = objApp.GetNamespace("MAPI")

  Set objUpdateContactsFolder = objNS.PickFolder()
  Set objExistingContactsFolder = objNS.PickFolder()

  Set objItemsUpdateContacts =
objUpdateContactsFolder.Items
  Set objItemsExistingContacts =
objExistingContactsFolder.Items

    For Each objItemUpdateContact In objItemsUpdateContacts
        Set FolioNumber = objItemUpdateContact.User1
        Set objItemExistingContact =
objItemsExistingContacts.Items.Restrict(FolioNumber)
            If objItemExistingContact Is Nothing Then
                objItemUpdateContact.Move
objExistingContactsFolder
            Else: objItemExistingContact.UserProperties
("Total Assets") = objItemUpdateContact.User2
            End If
    Next

  Set objApp = Nothing
  Set objNS = Nothing
  Set objExistingContactsFolder = Nothing
  Set objUpdateContactsFolder = Nothing
  Set objItemsUpdateContacts = Nothing
  Set objItemsExistingContacts = Nothing
  Set objItemUpdateContact = Nothing
  Set objItemExistingContact = Nothing
  Set FolioNumber = Nothing

End Sub



Sat, 30 Apr 2005 03:49:26 GMT  
 Code to update Existing Contact Information
I'm having a little trouble with the Find method.  I think
I should have the filter as "[Folio Number] = " & Quote
(FolioNumber)" instead of "[User1] = " & Quote
(FolioNumber) - I had previously copied the User1 data to
a userproperty field called Folio Number  for the items in
objItemsExistingContacts (you helped me with that one on
Friday morning), however, when I step through the program
with the de{*filter*} (which I thought was a great break
through for me), an error saying 'the property "Folio
Number" is unknown'

so now this is how my code is looking:

Oh yeah - it took me a little while to figure out that I
had to put the Quote function in myself, I'm thankful the
book has a good index!

And - Since some of the ItemUpdateContacts are to be moved
to the ExistingContactsFolder, I added code to change the
form of the ItemUpdateContacts to the same form as the
ItemExistingContacts and copy the User1,2,3 data to the
corresponding userproperty fields on the new form of the
ItemUpdateContacts. After I originally changed it to copy
the data over then clear the User1,2,3 fields I ran into
an error when I would subsequently run through the code -
I think it was because I was trying to copy a field valued
as Nothing, so I put in the If...Then statements to see if
I had previously cleared the User1,2,3 values for the
ItemUpdateContact.

Sub UpdateUserPropertyOrCopyInNewContact()

  Dim strFolioNumber As String
  Dim strFind As String

    For Each objItemUpdateContact In objItemsUpdateContacts
        If objItemUpdateContact.MessageClass
<> "IPM.Contact.FullContact" Then
           objItemUpdateContact.MessageClass
= "IPM.Contact.FullContact"
        End If

        If objItemUpdateContact.User1 <> "" Then
            objItemUpdateContact.UserProperties("Folio
Number") = objItemUpdateContact.User1
        End If

        If objItemUpdateContact.User2 <> "" Then
            objItemUpdateContact.UserProperties("Total
Assets") = objItemUpdateContact.User2
        End If

        If objItemUpdateContact.User3 <> "" Then
            objItemUpdateContact.UserProperties("IA Code")
= objItemUpdateContact.User3
        End If

        objItemUpdateContact.User1 = ""
        objItemUpdateContact.User2 = ""
        objItemUpdateContact.User3 = ""

        objItemUpdateContact.Save

        strFolioNumber =
objItemUpdateContact.UserProperties("Folio Number")
        strFind = "[Folio Number] = " & Quote
(strFolioNumber)

        Set objItemExistingContact =
objItemsExistingContacts.Find(strFind)
            If objItemExistingContact Is Nothing Then
                objItemUpdateContact.Move
objExistingContactsFolder
            Else: objItemExistingContact.UserProperties
("Total Assets") = objItemUpdateContact.User2
            End If
    Next

Thanks very much for your help,

Trevor

Quote:
 >-----Original Message-----
>It actually looks like you're making a lot of progress. 1

& 2 should be working fine.
Quote:

>#3a is the step to tackle next -- looking for a matching

item. This is what you have so far:
Quote:

>      Dim FolioNumber As Object
>    <snip>
>    Set FolioNumber = objItemUpdateContact.User1
>    Set objItemExistingContact =

objItemsExistingContacts.Items.Restrict(FolioNumber)
Quote:

>There are 4 basic problems with this:

>1) ContactItem.User1 is a string property, not an object

property. (You can look this kind of thing up in the
object browser.)
Quote:

>2) You use Set only with object variables, not with
string variables.

>3) If you're looking for just one matching item, Find is

more efficient than Restrict.
Quote:

>4) Your Restrict string only tells Outlook what value to

look for. It doesn't specify where to look for it. The
Find/Restrict string must always be an expression that
includes a) the field where you want to look, b) an
operator, such as = or >, and c) the value you want to
look for. This is covered in great detail in TYO2KP on pp.
261-3. Note that a string value will need surrounding
quotation marks.
Quote:

>Best practice is to build the Find/Restrict string

separately. This makes it easy to use a MsgBox or
Debug.Print statement to test the value.
Quote:

>When you need to include the value of a string variable,

you can make the code more readable by using the simple
Quote() function found on page 133 to add the quotation
marks.
Quote:

>Keeping those basics in mind, your code would look
something like:

>    Dim FolioNumber As String
>    Dim strFind as String
>    <snip>    
>    FolioNumber = objItemUpdateContact.User1
>    strFind = "[User1] = " & Quote(FolioNumber)
>    Set objItemExistingContact =

objItemsExistingContacts.Restrict(strFind)
Quote:

>Let's see if that gets you to the next step

>--
>Sue Mosher, Outlook MVP
>Outlook and Exchange solutions at http://www.*-*-*.com/
>Author of
>     Microsoft Outlook Programming: Jumpstart
>     for Administrators, Power Users, and Developers
>     http://www.*-*-*.com/




Quote:
>> My previous post was replied to by Sue Mosher
indicating I
>> would need custom code to do this:  This is my sad
>> attempt.  

>> I've been working with the TYO2000IN24HRS and am quite
>> obviously still confused:  I would like the code below
to
>> 1)Choose a Folder with updated contact information 2)
>> Choose a Folder with existing contact information 3)
For
>> each item in '1' a)check if there is a contact in '2'
with
>> the same value for a user property b)if there isn't,
move
>> the item from '1' to '2' c) if there is, copy the value
of
>> a 2nd user property in '1' to the corresponding field
>> in '2'.  And now that I think about it, for b) the code
>> will also have to copy the 2nd user property to the
>> corresponding field once the contact has been moved
to '2'.

>> Any suggestions on how to make the code more readable
will
>> be greatly appreciated as well.

>> And since you are probably laughing by now, consider
the
>> tears of laughter I have brought to your eyes a little
>> gift from me to say thank you for the help I'm hoping
to
>> receive.

>> And one more thing - I am starting to re-read the book
>> tonight and will spend much more time on each topic,
>> making sure I understand it before I move to the next
>> topic.

>> Sub UpdateUserPropertyOrCopyInNewContact()

>>   Dim objApp As Application
>>   Dim objNS As NameSpace
>>   Dim objExistingContactsFolder As MAPIFolder
>>   Dim objUpdateContactsFolder As MAPIFolder
>>   Dim objItemsUpdateContacts As Items
>>   Dim objItemsExistingContacts As Items
>>   Dim objItemUpdateContact As Object
>>   Dim objItemExistingContact As Object
>>   Dim FolioNumber As Object

>>   Set objApp = CreateObject("Outlook.Application")
>>   Set objNS = objApp.GetNamespace("MAPI")

>>   Set objUpdateContactsFolder = objNS.PickFolder()
>>   Set objExistingContactsFolder = objNS.PickFolder()

>>   Set objItemsUpdateContacts =
>> objUpdateContactsFolder.Items
>>   Set objItemsExistingContacts =
>> objExistingContactsFolder.Items

>>     For Each objItemUpdateContact In

objItemsUpdateContacts

- Show quoted text -

Quote:
>>         Set FolioNumber = objItemUpdateContact.User1
>>         Set objItemExistingContact =
>> objItemsExistingContacts.Items.Restrict(FolioNumber)
>>             If objItemExistingContact Is Nothing Then
>>                 objItemUpdateContact.Move
>> objExistingContactsFolder
>>             Else: objItemExistingContact.UserProperties
>> ("Total Assets") = objItemUpdateContact.User2
>>             End If
>>     Next

>>   Set objApp = Nothing
>>   Set objNS = Nothing
>>   Set objExistingContactsFolder = Nothing
>>   Set objUpdateContactsFolder = Nothing
>>   Set objItemsUpdateContacts = Nothing
>>   Set objItemsExistingContacts = Nothing
>>   Set objItemUpdateContact = Nothing
>>   Set objItemExistingContact = Nothing
>>   Set FolioNumber = Nothing

>> End Sub
>.



Sat, 30 Apr 2005 11:26:34 GMT  
 Code to update Existing Contact Information
I figured out the problem with the Find method - I needed
to add Folio Number to the ExistingContacts folder.

TDR

Quote:
>-----Original Message-----
>I'm having a little trouble with the Find method.  I
think
>I should have the filter as "[Folio Number] = " & Quote
>(FolioNumber)" instead of "[User1] = " & Quote
>(FolioNumber) - I had previously copied the User1 data to
>a userproperty field called Folio Number  for the items
in
>objItemsExistingContacts (you helped me with that one on
>Friday morning), however, when I step through the program
>with the de{*filter*} (which I thought was a great break
>through for me), an error saying 'the property "Folio
>Number" is unknown'

>so now this is how my code is looking:

>Oh yeah - it took me a little while to figure out that I
>had to put the Quote function in myself, I'm thankful the
>book has a good index!

>And - Since some of the ItemUpdateContacts are to be
moved
>to the ExistingContactsFolder, I added code to change the
>form of the ItemUpdateContacts to the same form as the
>ItemExistingContacts and copy the User1,2,3 data to the
>corresponding userproperty fields on the new form of the
>ItemUpdateContacts. After I originally changed it to copy
>the data over then clear the User1,2,3 fields I ran into
>an error when I would subsequently run through the code -
>I think it was because I was trying to copy a field
valued
>as Nothing, so I put in the If...Then statements to see
if
>I had previously cleared the User1,2,3 values for the
>ItemUpdateContact.

>Sub UpdateUserPropertyOrCopyInNewContact()

>  Dim strFolioNumber As String
>  Dim strFind As String

>    For Each objItemUpdateContact In

objItemsUpdateContacts

- Show quoted text -

Quote:
>        If objItemUpdateContact.MessageClass
><> "IPM.Contact.FullContact" Then
>           objItemUpdateContact.MessageClass
>= "IPM.Contact.FullContact"
>        End If

>        If objItemUpdateContact.User1 <> "" Then
>            objItemUpdateContact.UserProperties("Folio
>Number") = objItemUpdateContact.User1
>        End If

>        If objItemUpdateContact.User2 <> "" Then
>            objItemUpdateContact.UserProperties("Total
>Assets") = objItemUpdateContact.User2
>        End If

>        If objItemUpdateContact.User3 <> "" Then
>            objItemUpdateContact.UserProperties("IA
Code")
>= objItemUpdateContact.User3
>        End If

>        objItemUpdateContact.User1 = ""
>        objItemUpdateContact.User2 = ""
>        objItemUpdateContact.User3 = ""

>        objItemUpdateContact.Save

>        strFolioNumber =
>objItemUpdateContact.UserProperties("Folio Number")
>        strFind = "[Folio Number] = " & Quote
>(strFolioNumber)

>        Set objItemExistingContact =
>objItemsExistingContacts.Find(strFind)
>            If objItemExistingContact Is Nothing Then
>                objItemUpdateContact.Move
>objExistingContactsFolder
>            Else: objItemExistingContact.UserProperties
>("Total Assets") = objItemUpdateContact.User2
>            End If
>    Next

>Thanks very much for your help,

>Trevor

> >-----Original Message-----
>>It actually looks like you're making a lot of progress.
1
>& 2 should be working fine.

>>#3a is the step to tackle next -- looking for a matching
>item. This is what you have so far:

>>      Dim FolioNumber As Object
>>    <snip>
>>    Set FolioNumber = objItemUpdateContact.User1
>>    Set objItemExistingContact =
>objItemsExistingContacts.Items.Restrict(FolioNumber)

>>There are 4 basic problems with this:

>>1) ContactItem.User1 is a string property, not an object
>property. (You can look this kind of thing up in the
>object browser.)

>>2) You use Set only with object variables, not with
>string variables.

>>3) If you're looking for just one matching item, Find is
>more efficient than Restrict.

>>4) Your Restrict string only tells Outlook what value to
>look for. It doesn't specify where to look for it. The
>Find/Restrict string must always be an expression that
>includes a) the field where you want to look, b) an
>operator, such as = or >, and c) the value you want to
>look for. This is covered in great detail in TYO2KP on
pp.
>261-3. Note that a string value will need surrounding
>quotation marks.

>>Best practice is to build the Find/Restrict string
>separately. This makes it easy to use a MsgBox or
>Debug.Print statement to test the value.

>>When you need to include the value of a string variable,
>you can make the code more readable by using the simple
>Quote() function found on page 133 to add the quotation
>marks.

>>Keeping those basics in mind, your code would look
>something like:

>>    Dim FolioNumber As String
>>    Dim strFind as String
>>    <snip>    
>>    FolioNumber = objItemUpdateContact.User1
>>    strFind = "[User1] = " & Quote(FolioNumber)
>>    Set objItemExistingContact =
>objItemsExistingContacts.Restrict(strFind)

>>Let's see if that gets you to the next step

>>--
>>Sue Mosher, Outlook MVP
>>Outlook and Exchange solutions at

http://www.*-*-*.com/

- Show quoted text -

Quote:
>>Author of
>>     Microsoft Outlook Programming: Jumpstart
>>     for Administrators, Power Users, and Developers
>>     http://www.*-*-*.com/



>>> My previous post was replied to by Sue Mosher
>indicating I
>>> would need custom code to do this:  This is my sad
>>> attempt.  

>>> I've been working with the TYO2000IN24HRS and am quite
>>> obviously still confused:  I would like the code below
>to
>>> 1)Choose a Folder with updated contact information 2)
>>> Choose a Folder with existing contact information 3)
>For
>>> each item in '1' a)check if there is a contact in '2'
>with
>>> the same value for a user property b)if there isn't,
>move
>>> the item from '1' to '2' c) if there is, copy the
value
>of
>>> a 2nd user property in '1' to the corresponding field
>>> in '2'.  And now that I think about it, for b) the
code
>>> will also have to copy the 2nd user property to the
>>> corresponding field once the contact has been moved
>to '2'.

>>> Any suggestions on how to make the code more readable
>will
>>> be greatly appreciated as well.

>>> And since you are probably laughing by now, consider
>the
>>> tears of laughter I have brought to your eyes a little
>>> gift from me to say thank you for the help I'm hoping
>to
>>> receive.

>>> And one more thing - I am starting to re-read the book
>>> tonight and will spend much more time on each topic,
>>> making sure I understand it before I move to the next
>>> topic.

>>> Sub UpdateUserPropertyOrCopyInNewContact()

>>>   Dim objApp As Application
>>>   Dim objNS As NameSpace
>>>   Dim objExistingContactsFolder As MAPIFolder
>>>   Dim objUpdateContactsFolder As MAPIFolder
>>>   Dim objItemsUpdateContacts As Items
>>>   Dim objItemsExistingContacts As Items
>>>   Dim objItemUpdateContact As Object
>>>   Dim objItemExistingContact As Object
>>>   Dim FolioNumber As Object

>>>   Set objApp = CreateObject("Outlook.Application")
>>>   Set objNS = objApp.GetNamespace("MAPI")

>>>   Set objUpdateContactsFolder = objNS.PickFolder()
>>>   Set objExistingContactsFolder = objNS.PickFolder()

>>>   Set objItemsUpdateContacts =
>>> objUpdateContactsFolder.Items
>>>   Set objItemsExistingContacts =
>>> objExistingContactsFolder.Items

>>>     For Each objItemUpdateContact In
>objItemsUpdateContacts
>>>         Set FolioNumber = objItemUpdateContact.User1
>>>         Set objItemExistingContact =
>>> objItemsExistingContacts.Items.Restrict(FolioNumber)
>>>             If objItemExistingContact Is Nothing Then
>>>                 objItemUpdateContact.Move
>>> objExistingContactsFolder
>>>             Else: objItemExistingContact.UserProperties
>>> ("Total Assets") = objItemUpdateContact.User2
>>>             End If
>>>     Next

>>>   Set objApp = Nothing
>>>   Set objNS = Nothing
>>>   Set objExistingContactsFolder = Nothing
>>>   Set objUpdateContactsFolder = Nothing
>>>   Set objItemsUpdateContacts = Nothing
>>>   Set objItemsExistingContacts = Nothing
>>>   Set objItemUpdateContact = Nothing
>>>   Set objItemExistingContact = Nothing
>>>   Set FolioNumber = Nothing

>>> End Sub
>>.

>.



Sat, 30 Apr 2005 11:45:52 GMT  
 Code to update Existing Contact Information
Now something strange is happening - If I step through the
entire code I don't get any errors, however, I also notice
that the code isn't picking up the next Folio Number to
find.  Also, if I just run the code it gives me an
error 'object variable or with block variable not set'

I'm tired so I'll regroup in the morning.

Quote:
>-----Original Message-----
>I figured out the problem with the Find method - I needed
>to add Folio Number to the ExistingContacts folder.

>TDR
>>-----Original Message-----
>>I'm having a little trouble with the Find method.  I
>think
>>I should have the filter as "[Folio Number] = " & Quote
>>(FolioNumber)" instead of "[User1] = " & Quote
>>(FolioNumber) - I had previously copied the User1 data
to
>>a userproperty field called Folio Number  for the items
>in
>>objItemsExistingContacts (you helped me with that one on
>>Friday morning), however, when I step through the
program
>>with the de{*filter*} (which I thought was a great break
>>through for me), an error saying 'the property "Folio
>>Number" is unknown'

>>so now this is how my code is looking:

>>Oh yeah - it took me a little while to figure out that I
>>had to put the Quote function in myself, I'm thankful
the
>>book has a good index!

>>And - Since some of the ItemUpdateContacts are to be
>moved
>>to the ExistingContactsFolder, I added code to change
the
>>form of the ItemUpdateContacts to the same form as the
>>ItemExistingContacts and copy the User1,2,3 data to the
>>corresponding userproperty fields on the new form of the
>>ItemUpdateContacts. After I originally changed it to
copy
>>the data over then clear the User1,2,3 fields I ran into
>>an error when I would subsequently run through the code -
>>I think it was because I was trying to copy a field
>valued
>>as Nothing, so I put in the If...Then statements to see
>if
>>I had previously cleared the User1,2,3 values for the
>>ItemUpdateContact.

>>Sub UpdateUserPropertyOrCopyInNewContact()

>>  Dim strFolioNumber As String
>>  Dim strFind As String

>>    For Each objItemUpdateContact In
>objItemsUpdateContacts
>>        If objItemUpdateContact.MessageClass
>><> "IPM.Contact.FullContact" Then
>>           objItemUpdateContact.MessageClass
>>= "IPM.Contact.FullContact"
>>        End If

>>        If objItemUpdateContact.User1 <> "" Then
>>            objItemUpdateContact.UserProperties("Folio
>>Number") = objItemUpdateContact.User1
>>        End If

>>        If objItemUpdateContact.User2 <> "" Then
>>            objItemUpdateContact.UserProperties("Total
>>Assets") = objItemUpdateContact.User2
>>        End If

>>        If objItemUpdateContact.User3 <> "" Then
>>            objItemUpdateContact.UserProperties("IA
>Code")
>>= objItemUpdateContact.User3
>>        End If

>>        objItemUpdateContact.User1 = ""
>>        objItemUpdateContact.User2 = ""
>>        objItemUpdateContact.User3 = ""

>>        objItemUpdateContact.Save

>>        strFolioNumber =
>>objItemUpdateContact.UserProperties("Folio Number")
>>        strFind = "[Folio Number] = " & Quote
>>(strFolioNumber)

>>        Set objItemExistingContact =
>>objItemsExistingContacts.Find(strFind)
>>            If objItemExistingContact Is Nothing Then
>>                objItemUpdateContact.Move
>>objExistingContactsFolder
>>            Else: objItemExistingContact.UserProperties
>>("Total Assets") = objItemUpdateContact.User2
>>            End If
>>    Next

>>Thanks very much for your help,

>>Trevor

>> >-----Original Message-----
>>>It actually looks like you're making a lot of progress.
>1
>>& 2 should be working fine.

>>>#3a is the step to tackle next -- looking for a
matching
>>item. This is what you have so far:

>>>      Dim FolioNumber As Object
>>>    <snip>
>>>    Set FolioNumber = objItemUpdateContact.User1
>>>    Set objItemExistingContact =
>>objItemsExistingContacts.Items.Restrict(FolioNumber)

>>>There are 4 basic problems with this:

>>>1) ContactItem.User1 is a string property, not an
object
>>property. (You can look this kind of thing up in the
>>object browser.)

>>>2) You use Set only with object variables, not with
>>string variables.

>>>3) If you're looking for just one matching item, Find
is
>>more efficient than Restrict.

>>>4) Your Restrict string only tells Outlook what value
to
>>look for. It doesn't specify where to look for it. The
>>Find/Restrict string must always be an expression that
>>includes a) the field where you want to look, b) an
>>operator, such as = or >, and c) the value you want to
>>look for. This is covered in great detail in TYO2KP on
>pp.
>>261-3. Note that a string value will need surrounding
>>quotation marks.

>>>Best practice is to build the Find/Restrict string
>>separately. This makes it easy to use a MsgBox or
>>Debug.Print statement to test the value.

>>>When you need to include the value of a string
variable,
>>you can make the code more readable by using the simple
>>Quote() function found on page 133 to add the quotation
>>marks.

>>>Keeping those basics in mind, your code would look
>>something like:

>>>    Dim FolioNumber As String
>>>    Dim strFind as String
>>>    <snip>    
>>>    FolioNumber = objItemUpdateContact.User1
>>>    strFind = "[User1] = " & Quote(FolioNumber)
>>>    Set objItemExistingContact =
>>objItemsExistingContacts.Restrict(strFind)

>>>Let's see if that gets you to the next step

>>>--
>>>Sue Mosher, Outlook MVP
>>>Outlook and Exchange solutions at
> http://www.*-*-*.com/
>>>Author of
>>>     Microsoft Outlook Programming: Jumpstart
>>>     for Administrators, Power Users, and Developers
>>>     http://www.*-*-*.com/



>>>> My previous post was replied to by Sue Mosher
>>indicating I
>>>> would need custom code to do this:  This is my sad
>>>> attempt.  

>>>> I've been working with the TYO2000IN24HRS and am
quite
>>>> obviously still confused:  I would like the code
below
>>to
>>>> 1)Choose a Folder with updated contact information 2)
>>>> Choose a Folder with existing contact information 3)
>>For
>>>> each item in '1' a)check if there is a contact in '2'
>>with
>>>> the same value for a user property b)if there isn't,
>>move
>>>> the item from '1' to '2' c) if there is, copy the
>value
>>of
>>>> a 2nd user property in '1' to the corresponding field
>>>> in '2'.  And now that I think about it, for b) the
>code
>>>> will also have to copy the 2nd user property to the
>>>> corresponding field once the contact has been moved
>>to '2'.

>>>> Any suggestions on how to make the code more readable
>>will
>>>> be greatly appreciated as well.

>>>> And since you are probably laughing by now, consider
>>the
>>>> tears of laughter I have brought to your eyes a
little
>>>> gift from me to say thank you for the help I'm hoping
>>to
>>>> receive.

>>>> And one more thing - I am starting to re-read the
book
>>>> tonight and will spend much more time on each topic,
>>>> making sure I understand it before I move to the next
>>>> topic.

>>>> Sub UpdateUserPropertyOrCopyInNewContact()

>>>>   Dim objApp As Application
>>>>   Dim objNS As NameSpace
>>>>   Dim objExistingContactsFolder As MAPIFolder
>>>>   Dim objUpdateContactsFolder As MAPIFolder
>>>>   Dim objItemsUpdateContacts As Items
>>>>   Dim objItemsExistingContacts As Items
>>>>   Dim objItemUpdateContact As Object
>>>>   Dim objItemExistingContact As Object
>>>>   Dim FolioNumber As Object

>>>>   Set objApp = CreateObject("Outlook.Application")
>>>>   Set objNS = objApp.GetNamespace("MAPI")

>>>>   Set objUpdateContactsFolder = objNS.PickFolder()
>>>>   Set objExistingContactsFolder = objNS.PickFolder()

>>>>   Set objItemsUpdateContacts =
>>>> objUpdateContactsFolder.Items
>>>>   Set objItemsExistingContacts =
>>>> objExistingContactsFolder.Items

>>>>     For Each objItemUpdateContact In
>>objItemsUpdateContacts
>>>>         Set FolioNumber = objItemUpdateContact.User1
>>>>         Set objItemExistingContact =
>>>> objItemsExistingContacts.Items.Restrict(FolioNumber)
>>>>             If objItemExistingContact Is Nothing Then
>>>>                 objItemUpdateContact.Move
>>>> objExistingContactsFolder
>>>>             Else:

objItemExistingContact.UserProperties

- Show quoted text -

Quote:
>>>> ("Total Assets") = objItemUpdateContact.User2
>>>>             End If
>>>>     Next

>>>>   Set objApp = Nothing
>>>>   Set objNS = Nothing
>>>>   Set objExistingContactsFolder = Nothing
>>>>   Set objUpdateContactsFolder = Nothing
>>>>   Set objItemsUpdateContacts = Nothing
>>>>   Set objItemsExistingContacts = Nothing
>>>>   Set objItemUpdateContact = Nothing
>>>>   Set objItemExistingContact = Nothing
>>>>   Set FolioNumber = Nothing

>>>> End Sub
>>>.

>>.

>.



Sat, 30 Apr 2005 11:55:29 GMT  
 Code to update Existing Contact Information
I've taken a fresh look at your suggestions against my
code (I now see that you had given me the page number of
the Quote() function).

I think I've tried to do too much without knowing what I
am really doing.

When I run the code this morning I don't get any errors
but what it seems to be doing is changing the form (as I
was hoping), then clearing the values of User1, User2, and
User3 instead of copying the values from these fields
to "Folio Number", "Total Assets", and "IA Code".  The
comparison I'm trying to do between my ItemUpdateContact
and the ItemExistingContact that I try to Find() isn't
working.  So the code then moves the contact to the
ExistingContactsFolder (as I was sort of hoping).

This is the code I woke up with:

Sub UpdateUserPropertyOrCopyInNewContact()

  Dim objApp As Application
  Dim objNS As NameSpace
  Dim objExistingContactsFolder As MAPIFolder
  Dim objUpdateContactsFolder As MAPIFolder
  Dim objItemsUpdateContacts As Items
  Dim objItemsExistingContacts As Items
  Dim objItemUpdateContact As Object
  Dim objItemExistingContact As Object
  Dim strFolioNumber As String
  Dim strFind As String

  Set objApp = CreateObject("Outlook.Application")
  Set objNS = objApp.GetNamespace("MAPI")

  Set objUpdateContactsFolder = objNS.PickFolder()
  Set objExistingContactsFolder = objNS.PickFolder()

  Set objItemsUpdateContacts =  
objUpdateContactsFolder.Items
  Set objItemsExistingContacts =
objExistingContactsFolder.Items

    For Each objItemUpdateContact In objItemsUpdateContacts
        If objItemUpdateContact.MessageClass
<> "IPM.Contact.FullContact" Then
           objItemUpdateContact.MessageClass
= "IPM.Contact.FullContact"
        End If

        If objItemUpdateContact.User1 <> "" Then
            objItemUpdateContact.UserProperties("Folio
Number") = objItemUpdateContact.User1
        End If

        If objItemUpdateContact.User2 <> "" Then
            objItemUpdateContact.UserProperties("Total
Assets") = objItemUpdateContact.User2
        End If

        If objItemUpdateContact.User3 <> "" Then
            objItemUpdateContact.UserProperties("IA Code")
= objItemUpdateContact.User3
        End If

        objItemUpdateContact.User1 = ""
        objItemUpdateContact.User2 = ""
        objItemUpdateContact.User3 = ""

        objItemUpdateContact.Save

        strFolioNumber =
objItemUpdateContact.UserProperties("Folio Number")
        strFind = "[Folio Number] = " & Quote
(strFolioNumber)

        Set objItemExistingContact =
objItemsExistingContacts.Find(strFind)
            If objItemExistingContact.UserProperties
("Folio Number") = "" Then
                objItemUpdateContact.Move
objExistingContactsFolder
            Else: objItemExistingContact.UserProperties
("Total Assets") = objItemUpdateContact.UserProperties
("Total Assets")
            End If
    Next

  Set objApp = Nothing
  Set objNS = Nothing
  Set objExistingContactsFolder = Nothing
  Set objUpdateContactsFolder = Nothing
  Set objItemsUpdateContacts = Nothing
  Set objItemsExistingContacts = Nothing
  Set objItemUpdateContact = Nothing
  Set objItemExistingContact = Nothing

End Sub

I'm thinking I should do things separately. I know I can
change the form that my ItemsUpdateContacts use, and I can
copy the User1,2,3 fields to my UserProperties - so maybe
I should accomplish this first then start again with my
comparison - what do you think?



Sat, 30 Apr 2005 23:58:40 GMT  
 Code to update Existing Contact Information
I have used the For Each Item... With... Next loop.  I
checked the help file for the Add method and all the
examples show a variable being set with the value of the
added property, so it seems the UserProperties.Add method
wanted to see an '='.  I used Set myProp1
= .UserProperties.Add("Folio Number", olText), then set
myProp1 to Nothing at the end of the procedure.  Is this
right? should I have to have an '=' for
the .UserProperties.Add() method to work?

The first steps are complete, now I'm going to spend a few
days working in the book and will come back if I get stuck.

I really appreciate your help, thanks for spending some
time with me on this.

I'm sure I'll be back soon!

Trevor

Quote:
>-----Original Message-----
>> I think I've tried to do too much without knowing what
I
>> am really doing.

>Possibly so. That's why I wrote the book to build skills

and understanding gradually.
Quote:

>> I'm thinking I should do things separately. I know I
can
>> change the form that my ItemsUpdateContacts use, and I
can
>> copy the User1,2,3 fields to my UserProperties - so
maybe
>> I should accomplish this first then start again with my
>> comparison - what do you think?

>I think that's a good plan

>> When I run the code this morning I don't get any errors
>> but what it seems to be doing is changing the form (as
I
>> was hoping), then clearing the values of User1, User2,
and
>> User3 instead of copying the values from these fields
>> to "Folio Number", "Total Assets", and "IA Code".  

>You might try doing this in two passes: First, change the

MessageClass of all the items to the new form. Then, loop
through again and copy the data from the User# fields to
the custom fields. In theory, it should work all in one
pass, but Outlook does some caching that isn't very well
understood.
Quote:

>Alternatively, reverse the order: Add the data to the

items, then change the class (always in that order)
Quote:

>With objItemUpdateContact
>    .UserProperties.Add("Folio Number", olText)
>    .UserProperties("Folio Number") = .User1

>    ' repeat above statements for Total Assets and IA Code

>    .MessageClass = "IPM.Contact.FullContact"
>    .Save
>End With

>That should work all in one pass.

>Do you want to try one of those approaches to complete

the data conversion? Then we can come back to the issue of
comparing and moving the items.

- Show quoted text -

Quote:

>--
>Sue Mosher, Outlook MVP
>Outlook and Exchange solutions at http://www.slipstick.com
>Author of
>     Microsoft Outlook Programming: Jumpstart
>     for Administrators, Power Users, and Developers
>     http://www.slipstick.com/books/jumpstart.htm

>.



Sun, 01 May 2005 23:47:57 GMT  
 Code to update Existing Contact Information

Quote:
> I think I've tried to do too much without knowing what I
> am really doing.

Possibly so. That's why I wrote the book to build skills and understanding gradually.

Quote:
> I'm thinking I should do things separately. I know I can
> change the form that my ItemsUpdateContacts use, and I can
> copy the User1,2,3 fields to my UserProperties - so maybe
> I should accomplish this first then start again with my
> comparison - what do you think?

I think that's a good plan

Quote:
> When I run the code this morning I don't get any errors
> but what it seems to be doing is changing the form (as I
> was hoping), then clearing the values of User1, User2, and
> User3 instead of copying the values from these fields
> to "Folio Number", "Total Assets", and "IA Code".  

You might try doing this in two passes: First, change the MessageClass of all the items to the new form. Then, loop through again and copy the data from the User# fields to the custom fields. In theory, it should work all in one pass, but Outlook does some caching that isn't very well understood.

Alternatively, reverse the order: Add the data to the items, then change the class (always in that order)

With objItemUpdateContact
    .UserProperties.Add("Folio Number", olText)
    .UserProperties("Folio Number") = .User1

    ' repeat above statements for Total Assets and IA Code

    .MessageClass = "IPM.Contact.FullContact"
    .Save
End With

That should work all in one pass.

Do you want to try one of those approaches to complete the data conversion? Then we can come back to the issue of comparing and moving the items.

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
     Microsoft Outlook Programming: Jumpstart
     for Administrators, Power Users, and Developers
     http://www.slipstick.com/books/jumpstart.htm



Sun, 01 May 2005 21:37:44 GMT  
 Code to update Existing Contact Information
Either way should work. See you soon!
Quote:

> I have used the For Each Item... With... Next loop.  I
> checked the help file for the Add method and all the
> examples show a variable being set with the value of the
> added property, so it seems the UserProperties.Add method
> wanted to see an '='.  I used Set myProp1
> = .UserProperties.Add("Folio Number", olText), then set
> myProp1 to Nothing at the end of the procedure.  Is this
> right? should I have to have an '=' for
> the .UserProperties.Add() method to work?



Mon, 02 May 2005 03:28:50 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Updating existing user defined field in Contact form

2. bring up the select contact dialog in code to return contact(s)

3. Updating a single OLE link for a record OR updating existing database

4. Insufficent key column information for updating and refreshing:Too many rows to update

5. Populating existing Contact Spouse field from CSV file

6. Sync outlook contacts with existing Access 2k tables?

7. How to populate a DL with existing contacts from an outlook folder

8. Editing existing contact items

9. Finding Contact Information

10. Accessing Exchange Address Book and Contact information

11. Add contact information to folder other than default folder

12. Contact information in Outlook Appointments

 

 
Powered by phpBB® Forum Software