PDA

View Full Version : Outlook 2007 Update Fields Thru Tasks



lms
02-01-2014, 02:05 PM
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]

lms
02-03-2014, 04:07 PM
Update today maybe?

lms
02-08-2014, 05:01 PM
Anybody have any thoughts on this?

lms
02-18-2014, 04:46 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.

lms
02-19-2014, 07:06 PM
What other forum should I post this to please to get help?

westconn1
02-23-2014, 03:16 AM
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
Nextwhere 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

lms
02-23-2014, 06:39 AM
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.

westconn1
02-24-2014, 04:06 AM
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?

lms
02-24-2014, 05:08 AM
So I don't understand what to change in the Module. Do simply replace it with what you wrote above as a code?

lms
02-24-2014, 07:15 AM
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.

westconn1
02-25-2014, 04:04 AM
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

lms
02-25-2014, 05:31 AM
Thanks. Will try. Do I add at the end of Next any code to save the changes as my code has myItem.save?

lms
02-25-2014, 08:38 AM
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

westconn1
02-25-2014, 01:04 PM
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

lms
02-25-2014, 01:23 PM
I have Outlook 2007.....should there be something to change as it does not recognize c = f.items(conts(cq)) as an object

westconn1
02-26-2014, 02:49 AM
did you check if conts has any values in the array?

lms
02-26-2014, 03:43 AM
Thank you. I do not know how to do what you asked. Can you please tell me how to check that out?

lms
02-27-2014, 09:40 PM
Any help from anyone? I appreciate it very very much!!

lms
02-28-2014, 06:43 PM
Any update re what i need to do to find out what the problem is?

lms
03-08-2014, 08:01 AM
Any further help please?