Link to home
Start Free TrialLog in
Avatar of altschuler
altschuler

asked on

Referencing the current view records only

I am using the code below to update a custom field in our contacts list. This code updates all of the records in the current folder. I would like to modify it to only update the displayed records (i.e. the records shown after I have applied a filter to the current view.) I am working in Outlook 2000. Can anyone suggest a modification?

Sub UpdateDateFields2()
 Dim objContactsFolder As Outlook.MAPIFolder
   Dim objContacts As Outlook.Items
   Dim strDateSelect As String
   Dim strDate As Date
   Dim objContact As Object
   Dim iCount As Integer

   ' Specify which contact folder to work with
   Set objContactsFolder = Outlook.ActiveExplorer.CurrentFolder
   Set objContacts = objContactsFolder.Items

   ' Prompt for field and date
   strDateSelect = InputBox("Enter the field to update.")
   strDate = InputBox("Enter date.")
 

   iCount = 0

   ' Process the changes
   For Each objContact In objContacts
      If TypeName(objContact) = "ContactItem" Then
        objContact.UserProperties.Find(strDateSelect) = strDate
        objContact.Save
        iCount = iCount + 1
      End If
   Next
   
   MsgBox "Number of contacts updated:" & Str$(iCount)

   ' Clean up
   Set objContact = Nothing
   Set objContacts = Nothing
   Set objContactsFolder = Nothing
End Sub
ASKER CERTIFIED SOLUTION
Avatar of brice123
brice123

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of altschuler
altschuler

ASKER

Thanks again. Perfect.