locked
Outlook 2007 Update Fields Thru Tasks RRS feed

  • General discussion

  • I have a code for a Userform that is connnected to  Module code, and when I select a list of different contacts without opening them, the Userform shows in the drop list difference fields that are in all contacts, and a select a field from the Userform and it shows the list of words I can put in each same field of all contacts I selected.

    So what I want to do, is when I create a task for different contacts, in task area is shows the name of each contact as usual.  So want to select the tasks as to the contacts I want to change the fields to, and then run the Userfom and change the fields of each contact of each Task.   

    So in looking at the two codes, does anyone know what to change so it changes the fields of each contact thru the tasks I select?


    Here is the Userform code and below it is the Module code that goes to the Userform:

    Private Sub btnRun_Click()
        Dim Field As String
        Dim value As String
        Field = Me.ddlFields.Text
        value = Me.ddlValues.Text
        
       
            UpdateContactFieldTasks Field, value
          
        Me.Hide
        
    End Sub

    Private Sub ddlFields_Change()

        Dim fld As String
        fld = Me.ddlFields.Text
        'Add your field related values here.
        
        Select Case fld

        Case "Status Date"
       
           For M = 1 To 12
            For i = 1 To Day(DateSerial(Year(Now), Month(Now) + M, 1) - 1)
                Me.ddlValues.addItem Format(DateSerial(Year(Now), Month(Now) + M - 1, i), "mmm-dd-yyyy")
            Next
        Next
        
        Case "First Status:"
        
    Me.ddlValues.addItem ""
    Me.ddlValues.addItem "Words"
    Me.ddlValues.addItem "Words"
    Me.ddlValues.addItem "Words"


        Case "Next Status Date:"
     For M = 1 To 12
            For i = 1 To Day(DateSerial(Year(Now), Month(Now) + M, 1) - 1)
                Me.ddlValues.addItem Format(DateSerial(Year(Now), Month(Now) + M - 1, i), "mmm-dd-yyyy")
            Next
        Next

        Case "Related Status"
    Me.ddlValues.addItem ""
    Me.ddlValues.addItem "Words"
    Me.ddlValues.addItem "Words"
    Me.ddlValues.addItem "Words"
    Me.ddlValues.addItem "Words"



        Case "Last Status Date"
      For M = 1 To 12
            For i = 1 To Day(DateSerial(Year(Now), Month(Now) + M, 1) - 1)
                Me.ddlValues.addItem Format(DateSerial(Year(Now), Month(Now) + M - 1, i), "mmm-dd-yyyy")
            Next
        Next

        Case "Last Status"
    Me.ddlValues.addItem ""
    Me.ddlValues.addItem "Words"
    Me.ddlValues.addItem "Words"
    Me.ddlValues.addItem "Words"
    Me.ddlValues.addItem "Words"



        Case "Follow-Up?"
            Me.ddlValues.addItem ""
            Me.ddlValues.addItem "Yes"
            Me.ddlValues.addItem "No"
            Me.ddlValues.addItem "Maybe"
            Me.ddlValues.addItem "Decide Later"
            
        Case "Date to Follow- Up"
      For M = 1 To 12
            For i = 1 To Day(DateSerial(Year(Now), Month(Now) + M, 1) - 1)
                Me.ddlValues.addItem Format(DateSerial(Year(Now), Month(Now) + M - 1, i), "mmm-dd-yyyy")
            Next
        Next

        Case "Next Step"
    Me.ddlValues.addItem ""
    Me.ddlValues.addItem "Words"
    Me.ddlValues.addItem "Words"
    Me.ddlValues.addItem "Words"
    Me.ddlValues.addItem "Words"
      
        End Select
        
    End Sub

    Private Sub UserForm_Initialize()
        'Add your field names here.
        
        Me.ddlFields.addItem "Status Date"
        Me.ddlFields.addItem "First Status:"
        Me.ddlFields.addItem "Next Status Date:"
        Me.ddlFields.addItem "Related Status"
        Me.ddlFields.addItem "Last Status Date"
        Me.ddlFields.addItem "Last Status"
        Me.ddlFields.addItem "Follow-Up?"
        Me.ddlFields.addItem "Date to Follow- Up"
        Me.ddlFields.addItem "Next Step"
            
    End Sub



    Public Sub UpdateContactFieldTasks(ByVal FieldName As String, ByVal myValue As String)

       Dim objApp As outlook.Application
       Dim myItem As outlook.ContactItem
       Dim X As Integer
       Dim Selected As Integer
       X = 1
        Set objApp = Application
        
        On Error Resume Next
        
            Select Case TypeName(objApp.ActiveWindow)
            Case "Explorer"
                For Each Item In objApp.ActiveExplorer.Selection
                Selected = objApp.ActiveExplorer.Selection.Count
                Do While X <= Selected
                    Set myItem = objApp.ActiveExplorer.Selection.Item(X)
                       
                    myItem.Visible = False
                    myItem.UserProperties.Item(FieldName).value = myValue
                                                           
                    myItem.Display
                    myItem.Save
                
                    X = X + 1
                Loop
                   
                Next
            
        End Select
         
        Set objApp = Nothing
        
    End Sub

    Saturday, February 1, 2014 9:19 PM

All replies

  • Hello Imseaz,

    It looks like you are going to connect contact items with task items. The Outlook object model doesn't provide any ready made properties for connecting them. But you can uniquely identify Outlook items by using the EntryID values. For example, you can store the list of connected items represented by their EntryID values. Here is what MSDN states for the EntryID property:

    A MAPI store provider assigns a unique ID string when an item is created in its store. Therefore, the EntryID property is not set for an Outlook item until it is saved or sent. The Entry ID changes when an item is moved into another store, for example, from your Inbox to a Microsoft Exchange Server public folder, or from one Personal Folders (.pst) file to another .pst file. Solutions should not depend on the EntryID property to be unique unless items will not be moved.

    You can store the list of entry IDs using the UserProperties collection of each items. Both type of items provide the UserProperties property which returns the corresponding collection (represents all the user properties for the Outlook item).

    Finally, you can get an instance of Outlook item using the GetItemFromID method of the NameSpace class. For example, the following example illustrates the use of the GetItemFromID method:

    Sub OutlookEntryID()
       ' If there are more than 500 contacts, change the following line:
       Dim MyEntryID(500) As String
       Dim StoreID As String
       Dim EntryID As String
    
       Set olns = Application.GetNamespace("MAPI")
       Set objFolder = olns.GetDefaultFolder(olFolderContacts)
       ' Get the StoreID, which is a property of the folder.
       StoreID = objFolder.StoreID
       ' Set objAllContacts equal to the collection of all contacts.
       Set AllContacts = objFolder.Items
       I = 0
       ' Loop to get all of the EntryIDs for the contacts.
       For Each Item In AllContacts
          I = I + 1
          MyEntryID(I) = Item.EntryID
       Next
       ' Randomly choose the 2nd contact to retrieve.
       Set Item = olns.GetItemFromID(MyEntryID(2), StoreID)
       Item.Display
    End Sub

    Saturday, February 1, 2014 9:39 PM
  • thanks....but actually I have code that when i select a task, it creates a email to the email address of the contact that comes with the task.....so it identifies the email address of the contact...so to me it should be away to identify the fields etc.....

    Also, I am not the technical person so don't understand what you wrote and how that can be used with respect to the tasks....as another code I have, I said, I select any list of contacts and it goes to the fields...so don't need to store the contacts unless there is someway to do it re the tasks

    I appreciate your help so so much!

    Saturday, February 1, 2014 9:48 PM
  • Update today maybe?
    Monday, February 3, 2014 11:06 PM
  • I am having difficulty understanding exactly what it is that you are trying to do.  Do you want to create one Task for each selected Contact?  If so, what do you want to do with each Task?

    Eric Legault (MVP: Outlook; About me)
    Outlook Appins: Store social media fields in your Outlook Contacts!
    Co-author, Microsoft Office 2013 Professional Step-By-Step

    Tuesday, February 4, 2014 4:14 PM
    Moderator
  • Hello Imseaz,

    I see the following two statements in your last reply:

    > actually I have code

    > I am not the technical person so don't understand what you wrote

    Note, the current forum is for developers. Based on the statements above I'd suggest hiring a developer or learn VBA basics before. I don't quite understand what exactly you are going to implement.

    Tuesday, February 4, 2014 5:23 PM
  • To Eric:

    Thanks for your questions.   The Userform code that I show above, creates a drop list for each name of a field from the Contacts.  And each drop list I can put in different words and on the date side, its a normal list of dates, and then when I run it, it puts want word or date I select to the Contact that I select in running the Userform.   And the Userfom  works from the Module code I posted above.

    So I am not trying to create a task.   After I create a task to a contact, I want to select the Task and run the Userform which will refer to the contact of the task and change the contact fields as said above.

    Tuesday, February 4, 2014 10:20 PM
  • If you want to select the Task in a folder, you need to set the Explorer.CurrentFolder property to the relevant Task folder.

    If you just want to get access to a specific TaskItem in your code, you'd need to either know its TaskItem.EntryID property and get it using NameSpace.GetItemFromID, or do a search using Items.Restrict or Items.Find in the Task folder (via Folder.Items).


    Eric Legault (MVP: Outlook; About me)
    Outlook Appins: Store social media fields in your Outlook Contacts!
    Co-author, Microsoft Office 2013 Professional Step-By-Step

    Tuesday, February 4, 2014 11:11 PM
    Moderator
  • Thanks much but don't understand what you said....I just need to have my Userform code and related Module Code got to the contacts of each task I select, as if I selected the contacts from a contact folder
    Wednesday, February 5, 2014 1:07 AM
  • Are you not talking about Task items in a Tasks folder??  If not, you need to explain in greater detail what you mean by "selecting a Task".

    Eric Legault (MVP: Outlook; About me)
    Outlook Appins: Store social media fields in your Outlook Contacts!
    Co-author, Microsoft Office 2013 Professional Step-By-Step

    Wednesday, February 5, 2014 3:28 AM
    Moderator
  • It is the Tasks that are in the Task folder. So if that means a Task item, thats what I select
    Wednesday, February 5, 2014 5:38 AM
  • Okay, then use Explorer.Selection to either read the Tasks you are selecting, or use Explorer.AddToSelection to select Tasks for the user.

    Eric Legault (MVP: Outlook; About me)
    Outlook Appins: Store social media fields in your Outlook Contacts!
    Co-author, Microsoft Office 2013 Professional Step-By-Step

    Wednesday, February 5, 2014 2:51 PM
    Moderator
  • thank you....where is Explorer.Selection or Explorer.AddToSelection?   And how does this affect selecting tasks as if I was selecting the contacts of the task, so I can change the fields of each contact thru the Task per the codes I posted at the beginning?
    Wednesday, February 5, 2014 2:56 PM
  • What do you mean by "selecting the contacts of the task"?  Did you add Contacts to the TaskItem.Links collection??

    How are you maintaining a relationship between a Task and a Contact?  How do you know that Task "A" belongs to Contact "B"?


    Eric Legault (MVP: Outlook; About me)
    Outlook Appins: Store social media fields in your Outlook Contacts!
    Co-author, Microsoft Office 2013 Professional Step-By-Step

    Wednesday, February 5, 2014 3:02 PM
    Moderator
  • there is a way that you can assign a task to a contact and at the bottom of the task which shows a field called contacts, there is the name of the contact that if you click on it, it opens the contact.  so if that is the TaskItem.Links, then that answers you question.........

    the code I posted changes the fields of contacts that I select.....so I just want to select tasks and it does the same to the contacts that are part of each TaskIteml.Links

    Wednesday, February 5, 2014 4:18 PM
  • Yes, Contact linking is referenced by the Links collection in the Outlook Object Model.  To access a linked Contact from a task, you need to get that item via ContactItem.Links.Item(x), where x is the ordinal position of the Task in the collection if there is more than one link.

    e.g.

    Set MyTask = myContact.Links.Item(1)
    MyTask.Display

    However, note that the Links collection is deprecated in Outlook 2013 and will return null:

    http://msdn.microsoft.com/en-us/library/office/jj228679.aspx


    Eric Legault (MVP: Outlook; About me)
    Outlook Appins: Store social media fields in your Outlook Contacts!
    Co-author, Microsoft Office 2013 Professional Step-By-Step

    Wednesday, February 5, 2014 4:46 PM
    Moderator
  • If possible, can you look at my original codes for the Useform and the  Module that is connected to the Useform, and show me what to change re the words you just posted and where?  That would be great as Module code refers to contacts not tasks...

    The Module code is the following title:

    Public Sub UpdateContactFieldTasks(ByVal FieldName As String, ByVal myValue As String)

     
    Wednesday, February 5, 2014 5:30 PM
  • Sorry, I cannot write the code for you.  I am however more than happy to answer specific questions about the Outlook Object Model.

    Eric Legault (MVP: Outlook; About me)
    Outlook Appins: Store social media fields in your Outlook Contacts!
    Co-author, Microsoft Office 2013 Professional Step-By-Step

    Wednesday, February 5, 2014 7:06 PM
    Moderator
  • That is definitely sounds like my last post there ;)

    Wednesday, February 5, 2014 7:14 PM
  • I would think that if you just look at my code and given what you all said, you can just tell me what to change....that would be very nice!
    Wednesday, February 5, 2014 7:57 PM
  • Based on what I was told, where do I put in and/or replace with the following lines? Set MyTask = myContact.Links.Item(1) MyTask.Display
    Saturday, February 8, 2014 6:59 PM
  • I have not heard back from anyone.   Is this not understanding?  I just need to change the code so it selects the contact that is assigned to the Task I select, so I change the fields of the contact selected.  Can anyone help on this please?.  Thank you.
    Tuesday, February 18, 2014 11:47 PM
  • Imseaz,

    Please understand that the current forum is for helping other developers and discussing issues developers may face when programming [for] Outlook. But not to write the code for you. If you need to get a ready-made solution you need to hire a developer.

    Wednesday, February 19, 2014 7:22 AM
  • What other forum should I post this to please?
    Thursday, February 20, 2014 2:05 AM
  • You can post a job offer to a freelance-related web site, not forums. Some of them are oDesk, PeoplePerHour and etc. You can try searching on the internet.
    Thursday, February 20, 2014 6:18 AM
  • Any help from anyone? I appreciate it very very much!!
    Friday, February 28, 2014 4:41 AM
  • We are happy to help you. Do you have any questions? What kind of help do you need?

    Friday, February 28, 2014 12:11 PM
  • Please look at the beginning of this thread as it is very clear what I need to do. Thanks much.
    Saturday, March 1, 2014 7:39 AM