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
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
>.