Outlook 2007 Update Fields Thru Tasks

Status
Not open for further replies.

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
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:

Code:
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
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
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
 

Forum Admin

Senior Member
So you want to select a task and update the associated contact? What field value do you want to send to contacts?
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
I have a long list of fields....so in the Userform it shows each field name and at the end of the top code the following is the list of fields and then each one show in the Useform code the different values that I can put in...so if there is something that the code needs to specific fields, the ones below are the fields that are after the words Me.ddlFields.addItem....so anyway to do this?

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"
 

Forum Admin

Senior Member
You want to add the value of each of these fields to custom fields in the contact or to the notes field of the contact?
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
To the custom fields. So above you for example see the field 'Next Step'. In the code where you see the Case of thar name, in adding tge vale, i have a list of words which show up as a droplist in the userform and whatever i select it puts it in the field Next Step of the contact.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
You'll need to do something like

ocontact.UserProperties.Item("FieldName"). = otask..UserProperties.Item("FieldName")

i can't test it since it uses custom forms, but after you set the value in tasks, you need to push that value back to the contact
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Where do i add what you wrote please,
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
The goal is to just change the fields of the contact that the task is assigned to . Not change a task field, just update the task re the contact.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Oh, then you need to read the fields in the contact and set the task field using those values.

otask.UserProperties.Item("FieldName"). = ocontact.UserProperties.Item("FieldName")
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
So what to change re the code so the fields and related words go to the fields of the Contact. AndSo where do I put that code line you just wrote down which updates the Task field from the contact i changed?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I can't test it since my outlook version doesn't use links, but you need to put it in the macro you are using to write the changes to the contact.

Assuming you are using this code, it would replace this line
myItem.UserProperties.Item(FieldName).value = myValue

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
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Thank you but I misunderstand. What code line do I replace [FONT=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]myItem.UserProperties.Item(FieldName).value = myValue ?[/FONT]
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
you need to replace

myItem.UserProperties.Item(FieldName).value = myValue

with

otask.UserProperties.Item("FieldName") = ocontact.UserProperties.Item("FieldName")

Don't forget to adjust your object names so they match throughout the macros.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
So also don't understand how to adjust your object names so they match throughout the macros.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I know you do, because we've been through it before. :)

The things in bold may need to be changed if you are using something different to identify the tasks and contact

otask.UserProperties.Item("FieldName") = ocontact.UserProperties.Item("FieldName")
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
I replaced what you told me to do and when I ran the Userform to change the fields of the contact that is assigned to the Task that I select, it does not change the fields but there is no error. What else to try please?
 
Status
Not open for further replies.
Top