Consulting

Results 1 to 20 of 20

Thread: Outlook 2007 Update Fields Thru Tasks

  1. #1
    VBAX Regular
    Joined
    Jul 2013
    Posts
    75
    Location

    Outlook 2007 Update Fields Thru Tasks

    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


    [/CODE]

  2. #2
    VBAX Regular
    Joined
    Jul 2013
    Posts
    75
    Location
    Update today maybe?

  3. #3
    VBAX Regular
    Joined
    Jul 2013
    Posts
    75
    Location
    Anybody have any thoughts on this?

  4. #4
    VBAX Regular
    Joined
    Jul 2013
    Posts
    75
    Location
    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.

  5. #5
    VBAX Regular
    Joined
    Jul 2013
    Posts
    75
    Location
    What other forum should I post this to please to get help?

  6. #6
    Is this not understanding?
    probably, i do not believe it is that hard to do, but without being able to test and know that the correct results are being achieved, hard to make suggestions

    as you are doing this code from within outlook, some of the code, to create and outlook application object, is not required

    For Each Item In objApp.ActiveExplorer.Selection
    Selected = objApp.ActiveExplorer.Selection.Count
    Do While X <= Selected
    Set myItem = objApp.ActiveExplorer.Selection.Item(X)
    both the for loop and the do loop are working with exactly the same object

    it is easy enough to update the userproperties to all users, 1 user or a list of users for each of the selected tasks, but i can not make any suggestion for users selected within a task
    below is code to do for all users
    Dim tsk As TaskItem, c As ContactItem, f As MAPIFolder
    Set f = Application.GetNamespace("mapi").GetDefaultFolder(olFolderContacts)
    For Each tsk In ActiveExplorer.Selection
    conts = Split(tsk.ContactNames, ",")
        For cq = 0 To UBound(conts)
            Set c = f.Items(conts(cq))
            c.UserProperties(fieldname) = Value
        Next
    Next
    where fieldname and value are passed variables as in your code above, if you want to update 1 contact or a list of contacts, you would need to pass that list to the procedure as well

  7. #7
    VBAX Regular
    Joined
    Jul 2013
    Posts
    75
    Location
    Thanks for your reply. The codes I posted above already work fine to change the fields of 1 or more selected contacts. The Useform code at the top refers to the Module code below it. And the Useform code refers the different fields each as a Case, and the droplist of words I add for each case are the options for each related field. So I would think it is the Module code to adjust to go to the contacts of selected Tasks. If you have a suggestion, I can try it and let everyone know the results. Thanks much.
    Last edited by lms; 02-23-2014 at 07:08 AM.

  8. #8
    The codes I posted above already work fine to change the fields of 1 or more selected contacts.
    as far as i can tell, the module code will change the userproperties field for the task, if that in turn changes the userproperties field for the selected contacts all well and good,

    when you have selected ddlvalues and ddlfields, click the button, then the useform calls the module, passing it a field and value from the dropdown lists

    so what exactly is the problem? what is not working at this point?

  9. #9
    VBAX Regular
    Joined
    Jul 2013
    Posts
    75
    Location
    So I don't understand what to change in the Module. Do simply replace it with what you wrote above as a code?

  10. #10
    VBAX Regular
    Joined
    Jul 2013
    Posts
    75
    Location
    Can you please just tell me what I need to change in the Module so when I select a Task , the Userform goes to the fields of the Contact that is assigned to the Task. You showed a code above but I don't know where to add it on the Module and what to also take out of Module I posted? Thanks so much as this would be wonderful if it works with the Tasks.

  11. #11
    just try replacing your module code with what i posted above, to see if does what you want, keep your code in case mine does not do the required task

  12. #12
    VBAX Regular
    Joined
    Jul 2013
    Posts
    75
    Location
    Thanks. Will try. Do I add at the end of Next any code to save the changes as my code has myItem.save?

  13. #13
    VBAX Regular
    Joined
    Jul 2013
    Posts
    75
    Location
    I did the following and as to c = f.items(conts(cq), there is the error an object cannot be found..

    Public Sub UpdateContactFieldTasks(ByVal FieldName As String, ByVal myValue As String)
    
    Dim tsk As taskItem, c As contactItem, f As MAPIFolder
    Set f = Application.GetNamespace("mapi").GetDefaultFolder(olFolderContacts)
    For Each tsk In ActiveExplorer.Selection
        conts = Split(tsk.ContactNames, ",")
        For cq = 0 To UBound(conts)
            Set c = f.items(conts(cq))
            c.UserProperties.Item(FieldName).value = myValue
        Next
    Next
    End Sub

  14. #14
    it works without error when i test
    there maybe some difference in outlook versions, i can not tell
    the next line i am unable to test as my contacts have no userproperties
    any code to save the changes as my code has myItem.save?
    c.save after changing the userproperties

    if you only need to save the userproperties of the task, you do not need to loop through the contacts at all

  15. #15
    VBAX Regular
    Joined
    Jul 2013
    Posts
    75
    Location
    I have Outlook 2007.....should there be something to change as it does not recognize c = f.items(conts(cq)) as an object

  16. #16
    did you check if conts has any values in the array?

  17. #17
    VBAX Regular
    Joined
    Jul 2013
    Posts
    75
    Location
    Thank you. I do not know how to do what you asked. Can you please tell me how to check that out?

  18. #18
    VBAX Regular
    Joined
    Jul 2013
    Posts
    75
    Location
    Any help from anyone? I appreciate it very very much!!

  19. #19
    VBAX Regular
    Joined
    Jul 2013
    Posts
    75
    Location
    Any update re what i need to do to find out what the problem is?

  20. #20
    VBAX Regular
    Joined
    Jul 2013
    Posts
    75
    Location
    Any further help please?

Posting Permissions

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