none
Outlook 2007 Code RRS feed

  • Question

  • I need a code that takes care of the following, and where do I put it.

    When I created the Task form, in the Page called P2, I added to the Page P2 from the Control Toolbox two text boxes, but have not added Fields to them yet.

    When I created the default form for contacts, I have added a Combobox and in the Value area as to Choose a Field is a Text Field that I created, the Type is "Dropbown", the Property to Use is "Value", and then under Possible Values, I wrote in a list of words and phrases where at the end of each phrase is ";" which under the Combobox, each phrase shows up part of a drop list, and I just identify which phrase I want to show in the Combobox field on the Contact.

    And the other type of Combobox as to Choose a Field, is a Date/Time field and nothing else to add to it, so in the field of the Date/Time in the Contact, I just type in the appropriate date.

    So when I open a contact and create the Task that is an Assign Task to the contact, or in the list of contacts, I click on a contact (not open it), go to Actions, Create, New Task For Contact, how can each "Text Box" in the Task receive the value decided from the drop list from a specific Combobox in the Contact.

    And as to the details that are needed re the code, in the Comboxbox that has a Text Field, the Display Name is "NextStepComboBox1" and the Text Field I created for it, the name is "Next Step"

    And as to the date Combobox, the Display Name is "TextBox3" and the Field I created for it, the name is "Date to Follow- Up"

    Does anyone know the code to use, where I should put it please, and how I need to, if so, add a Field to each Textbox?

    Thanks very much.

    Tuesday, June 18, 2013 8:23 PM

Answers

  • Don't worry about the names of the controls.  It is the names of the fields that are bound to the controls that you would work with.  For example, if you bind a field to a default property then you access that property directly, such as ContactItem.CompanyName. 

    If you bind to a custom field, then use ContactItem.UserProperties("MyFieldName") to access the field.  When field values change, the PropertyChange or CustomPropertyChange events fire - then you can write to other fields in that event if you want to update a field based on the data in another field.


    Eric Legault (MVP: Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Monday, June 24, 2013 2:52 PM
    Moderator
  • There's plenty of documentation available on accessing UserProperties and item properties:

    Getting the Value of a Property
    http://msdn.microsoft.com/en-us/library/ff870127.aspx

    ContactItem.CustomPropertyChange Event (Outlook)
    http://msdn.microsoft.com/en-us/library/ff864389.aspx

    ContactItem.PropertyChange Event (Outlook)
    http://msdn.microsoft.com/en-us/library/ff864009.aspx


    Eric Legault (MVP: Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Tuesday, June 25, 2013 2:49 PM
    Moderator

All replies

  • So you want the value of a control to be updated when the value of another control changes?  Assuming both controls are bound to a field, monitor the PropertyChange or CustomerPropertyChange event (depending on whether the control is bound to a default field or a custom one), then read the source field's data and write it to the destination field.

    Manipulating Controls Programmatically
    http://msdn.microsoft.com/en-us/library/jj973065.aspx



    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Wednesday, June 19, 2013 2:12 PM
    Moderator
  • Thanks.   I am not a technical specialist so please tell me the details of how to do what you are saying as I don't know the concepts even.   An example, I don't know what controls are as I just have the textboxes and the comboboxs and I don't understand the concept of bound to a field or how to monitor and what to see where and where to write it.

    Can you give me the details please?  Thanks so much.

    Wednesday, June 19, 2013 7:54 PM
  • But if I provided deeper details then I'd just be using more concepts that you don't know! I strongly suggest you get a grasp on the basics of custom form development before you go any further.  When you have a more clear idea of what you need to figure out and thus the tools to solve your problems, I'd be more than happy to provide further guidance. 

    This is the best place to start:

    Microsoft Outlook Custom Forms
    http://www.outlookcode.com/article.aspx?ID=35


    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Wednesday, June 19, 2013 9:03 PM
    Moderator
  • Thanks again.

    I do know how to design the forms and where it says View Code that you put in, and I know how to publish it and use it as a default form.

    So is there a code to use and where to put it please?



    • Edited by lmseaz Wednesday, June 19, 2013 9:14 PM Upgrade Thread
    Wednesday, June 19, 2013 9:09 PM
  • I've provided you with links that will help you determine what code you need.  If you want someone to write the code for you, I suggest you contact Microsoft Support Services.

    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Wednesday, June 19, 2013 9:14 PM
    Moderator
  • Thanks for your time.
    Wednesday, June 19, 2013 9:17 PM
  • I have read what you told me to read, and I understand how to get the real name of the Combobox that I want to be the sourse to the Textbox in the Task, but it is not clear to me what I read that shows the field's data and how you can change the data of a differnent field.

    So if this is easy to explain, I appreciate it.   It sounds like get the data of the field from the ComboBox and then replace that data into the field of the Textbox, so whatever I change in the Combobox, it automatically changes the the Textbox. 

    Again, I could not find where the data is for each field.   All that shows up in the areas I read, is the name of the field.

    I appreciate your help if this is easy to do!

    Saturday, June 22, 2013 8:56 PM
  • And I want to mention that it is the data from the Combobox in the Contact to which the Task is assigned to.
    Saturday, June 22, 2013 9:17 PM
  • Don't worry about the names of the controls.  It is the names of the fields that are bound to the controls that you would work with.  For example, if you bind a field to a default property then you access that property directly, such as ContactItem.CompanyName. 

    If you bind to a custom field, then use ContactItem.UserProperties("MyFieldName") to access the field.  When field values change, the PropertyChange or CustomPropertyChange events fire - then you can write to other fields in that event if you want to update a field based on the data in another field.


    Eric Legault (MVP: Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Monday, June 24, 2013 2:52 PM
    Moderator
  • Can you please explain to me what to write down and where to put it please?
    Tuesday, June 25, 2013 2:45 PM
  • There's plenty of documentation available on accessing UserProperties and item properties:

    Getting the Value of a Property
    http://msdn.microsoft.com/en-us/library/ff870127.aspx

    ContactItem.CustomPropertyChange Event (Outlook)
    http://msdn.microsoft.com/en-us/library/ff864389.aspx

    ContactItem.PropertyChange Event (Outlook)
    http://msdn.microsoft.com/en-us/library/ff864009.aspx


    Eric Legault (MVP: Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Tuesday, June 25, 2013 2:49 PM
    Moderator
  • In the form of the Contact, the first combobox that I want to get the value from to the Textbox in the Task form where the Task is assigned to the contact, has the Display Name: "ComboBox7" and the Field that was created relative to ComboBox7, is: "Advisory Area"

    And the Textbox in the form of the Taskform, is “Textbox20” and not with any field as a part of it.

    Here is the code I was given. I put it in a new Module and created the commandbotton to it in the form of the contacts, then I ran it from a contact I opened.


    Sub CommandButton1_Click()
    Dim Str
    Dim myItem

    Str =Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox7").Value
    Set myItem =Application.CreateItemFromTemplate("C:\Users\Louis\AppData\Roaming\Microsoft\Templates\TaskFollow-Up Template.oft")
    myItem.Display

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox20").Value= Str

    'MsgBox Str
    End Sub

    And the debug shows up with the yellow color on the line: “Str =Item.GetInspector.ModifiedFormPages("General" ).Controls("ComboBox7").Value” and error is:

    "Run Time Error 424

    Object Required"

    I read thru the above code I was given and it seems that it basically is that the "myitem" is the Task template and the TextBox20 which is a part of the "P.2" of the Task form, gets its value from the "Str".

     So is there a way, to refer to the Value of the ComboBox7 in the "Str" so it goes to the "myitem" TextBox20 area when you run the macro creating a Task asssigned to the contact you opened?

    Saturday, June 29, 2013 8:11 PM
  • The first Str assignment should be this:

         Str = Item.GetInspector.ModifiedFormPages("P.2").Controls("ComboBox7").Value

    Correct? P.2 instead of General?


    Eric Legault (MVP: Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Tuesday, July 2, 2013 3:05 PM
    Moderator
  • Here is the Code that is working at a certain level and which is put in the View Code/Script Editor of the form of the Contact.

    Sub CommandButton4_Click
    Dim Str,Str1,
    Dim myItem


    Str = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox7").Value
    Str1 = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox8").Value
    Set myItem = Application.CreateItemFromTemplate ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\Task Follow-Up.oft")
    myItem.Display

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox20").Value = Str
    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox7").Value = Str1


    End Sub

    This code is working by drafting it this way:
    In the contact form, there is the new CommandButton4.
    In the Str lines, each line refers to a ComboBox in the form of the Contact, and the ( ) area after "Controls" is the Display Name of the the Combobox.
    The Set myItem line, refers to the the form of the Task form that I added the Textbox(s) to, and saved to my template area.
    In the myItem line, the ("P.2") refers to the Page 2 of the Task form, and the the area ( ) after Controls is the Display Name of the TextBox that is to get the Value from the particular ComboBox of a Str line.
    And when I created the Task P.2 area, that's where I put in the TextBox(s) and I created a new field for each one so it is stored.

    So the next problem to fix, is that when I click on the CommandButton4 in a contact, it creates the Task and it puts in the TextBox(s) the values from the ComboBox(s) of the Contact I am doing it from, but it does not assign the Task to the contact and show the link of the contact at the bottom of the Task, which is what it would normally do in the Assign Task of a Contact. Is there a way to fix this??


    And the second area, is after a Task is created per this process, and I later change a value in a ComboBox of the Contact that gets assigned to the Task, how can it upgrade the TextBox(s) of the Task with the current Value?


    Thanks so much.

    Tuesday, July 2, 2013 9:23 PM
  • To get the value of a field when it changes, you have to monitor the PropertyChange or CustomPropertyChange event.  If a control is not bound to a field, you cannot detect when the value changes as the only events available to custom controls is the Click event.

    To assign the task, call TaskItem.Assign:

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


    Eric Legault (MVP: Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Tuesday, July 2, 2013 9:56 PM
    Moderator
  • Thanks for your time.  Please explain what you mean by "call TaskItem.Assign"

    As my code is in the code of the contact, what code do I add to it and where in the code,  so it links to the contact when I click on the command botton that creates the task and adds the values of the contact comboboxes to the textboxes in the Task?

    Tuesday, July 2, 2013 10:56 PM
  • Assign is a method of the TaskItem object, that assigns the task to a specified Contact/email address.

    To link an item to a Contact, add the Contact object to the item's Links collection:

    http://msdn.microsoft.com/en-us/library/ff868983%28v=office.14%29.aspx


    Eric Legault (MVP: Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Wednesday, July 3, 2013 5:56 AM
    Moderator
  • Thank-you very much! I am not an expert re codes and just get it from others. Can you please type in the code I need and explain where I add it. As the code I showed above is in the View Code/ Script of the contact form. So do I put the next code in the View Code/ Script of the Task form so when I click in the CommandButton4 in the Contact and it creates the Task from the Task form, the code in the Task form assignes the contact?
    Wednesday, July 3, 2013 6:26 AM
  • I don't completely understand the full range of actions and functionality that you are trying to implement.  I've reread your posts several times and I'm not completely sure if you are creating a Task from a custom Contact form, a Task from a custom Task form, or something else.

    Regardless, I cannot write the code for you.  I am here to assist others who are trying to learn Outlook programming.  If you don't understand the basics of working with the code editor, or using events and accessing control properties, then I suggest you spend some time reading; OutlookCode.com is a great reference:

    Microsoft Outlook Custom Forms
    http://www.outlookcode.com/article.aspx?ID=35


    Eric Legault (MVP: Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Wednesday, July 3, 2013 3:22 PM
    Moderator
  • I read thru the link you gave me: 

    http://msdn.microsoft.com/en-us/library/ff868983%28v=office.14%29.aspx

    But the VBA it shows, when you run it, there is an errror prior to that, it asks you to type in a name as a link, not just linking to the contact that you are running the macro from.

    Here is the code: and the words:  "myTask.Links.Add myContact" is the error showing up.

    Can you think of anything to fix so this code links to contact autumatically and puts in the Contact area of the Task as if it was an assigned task? 

    Sub AddLink()

    Dim myNameSpace As Outlook.NameSpace

    Dim myFolder As Outlook.Folder

    Dim myTask As Outlook.TaskItem

    Dim myContact As Outlook.ContactItem

    Dim myItems As Outlook.Items

    Dim tempstr As String



    Set myTask = Application.CreateItem(olTaskItem)

    Set myNameSpace = Application.GetNamespace("MAPI")

    Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)

    tempstr = InputBox("Enter the name of the contact to link to this task")

    If tempstr <> "" Then

    tempstr = "[Full Name] = """ & tempstr & """"

    Set myItems = myFolder.Items.Restrict("[MessageClass] = 'IPM.Contact'")

    Set myContact = myItems.Find(tempstr)

    myTask.Links.Add myContact

    myTask.Display

    End If

    End Sub

    Thursday, July 4, 2013 1:06 AM
  • The code sample for the Links.Add method is not meant to be run from a custom form as it is VBA and not VBScript. However, you can easily modify it to work with your solution.  The key concept to understand is that if you want to link an item to a Contact, get a ContactItem object for the Contact you want to link to and add that object it to the Links collection for the source item (the Task I believe for your solution).

    I think you got an error running the code because it couldn't find a Contact for the text you entered and it's not checking to make sure myContact is not Nothing.


    Eric Legault (MVP: Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Thursday, July 4, 2013 1:38 AM
    Moderator
  • So what do I change and do i just add it to the script of the contact below the current code in the script? And is get a ContactObject just typing in the full name of the Contact?? Thanks much.
    • Edited by lmseaz Thursday, July 4, 2013 3:24 AM Thanks again!
    Thursday, July 4, 2013 3:21 AM
  • Add the linking code to wherever it's supposed to go - when the user clicks one of your buttons??  You haven't shown any of your code nor carefully explained what it is you're trying to do exactly, so I've had to guess.

    If the code is running in a custom Contact form, and that is the Contact you want to link to, the intrinsic Item object is the current Contact so just add Item to the Links collection.  If you just created the Contact from a custom Task form, you already have the Contact object - it's returned from the Items.Add or NameSpace.CreateItem methods.


    Eric Legault (MVP: Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Thursday, July 4, 2013 4:23 AM
    Moderator
  • Thanks again.  I will explain in details just in case you can tell me in details how I add Item to the Links collection, as i don't know where those places are, and what words to adjust the the code and where to put the code.

    I have a new form for Contacts that is named IPM.Contact.Contact Form 1, and it is published to the Personal Folder and is the default form for all Contacts.

    I have a new form for the Tasks that is "Task Follow-Up" that is saved in the Template area as Task Follow-Up.oft, and it is published in both the Personal Folder and the Outlook folder, and is the default for for all Tasks.

    The code as follows is in the Script area of the Contact form, and the Contact form has the CommandButton4, and when I open a Contact, I click on the CommandButton4, it creates the Task from the default form, and it put's Values of certain Comboboxes in the Contact in the TextBoxes in the Task that is created.

    So below is code, and the questions are:

    What should be changed to the link code, and where do I put the link code.

    Secondly, please explain how you add the word Item to the Links collection.  I don't understand it.

    Sub CommandButton4_Click
    Dim Str,Str1,
    Dim myItem


    Str = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox7").Value
    Str1 = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox8").Value
    Set myItem = Application.CreateItemFromTemplate ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\Task Follow-Up.oft")
    myItem.Display

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox20").Value = Str
    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox7").Value = Str1


    End Sub

    This code is working by drafting it this way:
    In the contact form, there is the new CommandButton4.
    In the Str lines, each line refers to a ComboBox in the form of the Contact, and the ( ) area after "Controls" is the Display Name of the the Combobox.
    The Set myItem line, refers to the the form of the Task form that I added the Textbox(s) to, and saved to my template area.
    In the myItem line, the ("P.2") refers to the Page 2 of the Task form, and the the area ( ) after Controls is the Display Name of the TextBox that is to get the Value from the particular ComboBox of a Str line.
    And when I created the Task P.2 area, that's where I put in the TextBox(s) and I created a new field for each one so it is stored.

    Thursday, July 4, 2013 1:12 PM
  • Add this line to the end of your button click event:

    myItem.Links.Add Item

    As I explained, Item is the intrinsic object variable for the active item running the code.


    Eric Legault (MVP: Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Thursday, July 4, 2013 3:25 PM
    Moderator
  • I put it at the end of the code before the words "End Sub" and published the form, and it does it perfectly!!

    I so appreciate you showing me how to do it!!! 

    So the last area to know how to do per what I posted, is what code to use and where to put it, so when I update the values of the Comboboxes in the Contact that is linked to the Task, the Textboxes that received the values from the Comboboxes are updated in the Task.  As you see the code, you know how the populated the value works, so how to refresh the populating.

    That would be wonderful if you can tell me now to do that right away as I have many things to update etc.

    Thanks again so so  much.

    • Edited by lmseaz Thursday, July 4, 2013 4:28 PM Updated comment
    Thursday, July 4, 2013 4:17 PM
  • You're welcome!  When the value for a standard field/property changes, the PropertyChange event will fire; CustomPropertyChange fires for custom fields.  I don't know what field you have bound to your combo boxes, but try pasting this code into your form as an example to show you what happens when values are changed:

    Sub Item_PropertyChange(ByVal Name)
         MsgBox "Property: " & Name
    End Sub
    
    Sub Item_CustomPropertyChange(ByVal Name)
         MsgBox "Field: " & Name
         
         Dim objField
    
         Set objField = Item.UserProperties(Name)
         MsgBox "Value: " & objField.Value
    End Sub


    Eric Legault (MVP: Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Thursday, July 4, 2013 5:11 PM
    Moderator
  • Thanks again.

    Do I put it below the End Sub of the first code in the Script of the Contact form?

    And are there words I need to replace re the code you just showed me based on the field name or dispaly name of the Comboboxes?

    In code I am using, the Value to a TextBox in the Task comes from either a Combobox or TextBox in the Contact, and the code I am using referes to the Display names not the field names.

    Or do I just paste what your wrote?

    Thursday, July 4, 2013 5:25 PM
  • Sub/End Sub blocks are discrete procedures/methods and can't be nested.  The order or location of these blocks within the full script doesn't matter.  Put it below.

    I don't know what fields you have bound to your controls!  The name of the field is what will be passed to the Name argument of those events.  Use the field name to access the value for the item property or custom field, and pass that to your controls on the other form.


    Eric Legault (MVP: Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Thursday, July 4, 2013 5:30 PM
    Moderator
  • I already put it in, and then when I changed the Value of a Combobox thru the droplilst, it shows up in the Contact a little box with the words:

    Field:  Advisory Area    and that the field name of the Combobox and then I click ok....and then is shows up a little box with the words:

    Value = (the words I picked from the combobox)   

    But it does not refresh the Task Textbox.

    The code lines that populates that first Combobox to the TextBox in the Task referng to the Combobox and TextBox , is the following:

    Str = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox7").Value

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox20").Value = Str

    Should I replace the words "Combobox7" which is the Display value of the Combobox to the words "Advisory Area" which is the field name of the Combobox

    And should I replace the words "TextBox20" which is the Display name of the Textbox to the name of the field of the Text box which is "Advisory Area: TB"


    Thursday, July 4, 2013 5:49 PM
  • Okay, now I now that "Advisory Area" is a custom field.  In the code I gave you it showed how to obtain a UserProperty object from the UserProperties collection using the name of a custom field.  So set Str to the value of that field instead of the value of the control.

    Keep the line of code that sets TextBox20 to Str; that part is correct as that is how you set the value of an unbound control.


    Eric Legault (MVP: Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Thursday, July 4, 2013 5:59 PM
    Moderator
  • I replaced

    Str = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox7").Value

    to:

    Str = Item.GetInspector.ModifiedFormPages("General").Controls("Advisory Area").Value

    And when I run the CommandButton4 to start, it says it does not recognize etc...

    So should I replace the words:  "Controls(ComBox7") just with the words Advisory Area?

    And if so, how do I format it in the line?

    Thursday, July 4, 2013 6:14 PM
  • Okay, you're going to need to slow down and carefully read what I've explained, because I've already showed you several times how to obtain the value from the field using a UserProperty object, NOT the control.

    You want:

    Dim objField 'This will be a UserProperty object

    'Get the UserProperty object from the item's UserProperties collection
    Set objField = Item.UserProperties("Advisory Area")
    'Get the value from the field
    Str = objField.Value
    'Set the control to the value obtained from the field
    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox20").Value = Str


    Eric Legault (MVP: Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Thursday, July 4, 2013 6:26 PM
    Moderator
  • Thanks so much but I don't have background of understanding.  And I assume this is just taken care of one str area, so here is the code I was given that worked and if please please can, just adjust this code and then I can do it for each str and related area.  And please don't add words that explain things on the code....just the code so i know what to use please.....thanks thanks thanks!!.

    Sub CommandButton4_Click
    Dim Str,Str1,
    Dim myItem


    Str = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox7").Value
    Str1 = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox8").Value
    Set myItem = Application.CreateItemFromTemplate ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\Task Follow-Up.oft")
    myItem.Display

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox20").Value = Str
    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox7").Value = Str1


    End Sub

    Thursday, July 4, 2013 6:36 PM
  • Please don't take this the wrong way, but if you're not a programmer - why are you programming?  The intent of this forum is to help people learn to build Outlook solutions, not to teach basic programming skills nor to write the code for them.  I strongly suggest you either contract this project out to a programmer, or invest time into learning the fundamentals of VBScript.

    Eric Legault (MVP: Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Thursday, July 4, 2013 6:48 PM
    Moderator
  • I understand. Lets finish this per you updating the code re what I said and i won't ask to keep doing it this way with another area. I appreciate it.
    Thursday, July 4, 2013 6:56 PM
  • I've already given you the code!  I don't know what else to say.

    Eric Legault (MVP: Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Thursday, July 4, 2013 7:03 PM
    Moderator
  • It's not clear to me what your code replaces and what I keep. So when  you give me the full code of all, as that shows me what is replaced and what is still there and where....,  And then when I do it for the str1, I use the same code a second time.

    Please let me know

    Thanks much.


    • Edited by lmseaz Thursday, July 4, 2013 7:27 PM Update Question
    Thursday, July 4, 2013 7:16 PM
  • I have 20 areas of the Contact field to the Tast field, and I added what you gave me re the str, not str1, str2 etc....

    And when I click on the commandbotton4 it gives me the error, "Object Required Myitem"

    Here is how I typed it in:

    Sub CommandButton4_Click

    Dim Str,Str1,Str2,Str3,Str4,Str5,Str6,Str7,Str8,Str9,Str10,Str11,Str12,Str13,Str14,Str15,Str16,Str17,Str18,Str19

    Dim myItem

     

    Dim objField 'This will be a UserProperty object

     

    'Get the UserProperty object from the item's UserProperties collection

    Set objField = Item.UserProperties("Advisory Area")

    'Get the value from the field

    Str = objField.Value

    'Set the control to the value obtained from the field

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox20").Value = Str

     

     

     

    Str1 = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox8").Value

    Str2 = Item.GetInspector.ModifiedFormPages("General").Controls("TextBox5").Value

    Str3 = Item.GetInspector.ModifiedFormPages("General").Controls("Initial Intro").Value

    Str4 = Item.GetInspector.ModifiedFormPages("General").Controls("Intro Date").Value

    Str5 = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox10").Value

    Str6 = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox3").Value

    Str7 = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox2").Value

    Str8 = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox4").Value

    Str9 = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox5").Value

    Str10 = Item.GetInspector.ModifiedFormPages("General").Controls("ContactTypeComboBox1").Value

    Str11 = Item.GetInspector.ModifiedFormPages("General").Controls("TextBox4").Value

    Str12 = Item.GetInspector.ModifiedFormPages("General").Controls("StatusComboBox1").Value

    Str13 = Item.GetInspector.ModifiedFormPages("General").Controls("TextBox20").Value

    Str14 = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox6").Value

    Str15 = Item.GetInspector.ModifiedFormPages("General").Controls("TextBox22").Value

    Str16 = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox9").Value

    Str17 = Item.GetInspector.ModifiedFormPages("General").Controls("Follow-Up ComboBox1").Value

    Str18 = Item.GetInspector.ModifiedFormPages("General").Controls("TextBox3").Value

    Str19 = Item.GetInspector.ModifiedFormPages("General").Controls("NextStepComboBox1").Value

     

    Set myItem = Application.CreateItemFromTemplate ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\Task Follow-Up.oft")

    myItem.Display

     

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox7").Value = Str1

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox24").Value = Str2

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox25").Value = Str3

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox26").Value = Str4

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox23").Value = Str5

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox8").Value = Str6

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox9").Value = Str7

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox10").Value = Str8

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox11").Value = Str9

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox12").Value = Str10

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox13").Value = Str11

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox14").Value = Str12

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox15").Value = Str13

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox16").Value = Str14

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox22").Value = Str15

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox21").Value = Str16

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox17").Value = Str17

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox18").Value = Str18

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox19").Value = Str19

     

    myItem.Links.Add Item

    End Sub

       

    Sub Item_PropertyChange(ByVal Name)

         MsgBox "Property: " & Name

    End Sub

    Sub Item_CustomPropertyChange(ByVal Name)

         MsgBox "Field: " & Name

              Dim objField

         Set objField = Item.UserProperties(Name)

         MsgBox "Value: " & objField.Value

    End Sub

       

    Thursday, July 4, 2013 8:39 PM
  • This line has to come before any other usages of myItem, or else the task hasn't been created yet and the variable will be null:

    Set myItem = Application.CreateItemFromTemplate ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\Task Follow-Up.oft")


    Eric Legault (MVP: Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Thursday, July 4, 2013 9:05 PM
    Moderator
  • And then I took out the second SubItem thinking that was getting in the way as we don't need it, and still the same error:

    Object Required: myItem

    How to fix this perhaps?

    Thanks much for your time.

    Thursday, July 4, 2013 9:18 PM
  • Sorry, but I'm going to have to excuse myself from this thread.  I can only support non-programmers to a certain degree - it's simply much too difficult and time consuming.  As I stated before - I'm here to help people learn to build Outlook solutions, not to teach basic programming or write your code for you.

    Eric Legault (MVP: Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Thursday, July 4, 2013 9:35 PM
    Moderator
  • I did what you said so that the set myitem re the task follow-up.ost is before the myitem but so he task worked....

    I put the second subitem code back in as it recognizes the changes to the value in the combobox...

    But it this did not update the related Textbox in the Task.

    Any other way to do it?

    Here is the formal code right now:

    Sub CommandButton4_Click

    Dim Str,Str1,Str2,Str3,Str4,Str5,Str6,Str7,Str8,Str9,Str10,Str11,Str12,Str13,Str14,Str15,Str16,Str17,Str18,Str19

    Dim myItem

    Dim objField 'This will be a UserProperty object

    'Get the UserProperty object from the item's UserProperties collection

    Set objField = Item.UserProperties("Advisory Area")

    'Get the value from the field

    Str = objField.Value

    'Set the control to the value obtained from the field

     

    Str1 = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox8").Value

    Str2 = Item.GetInspector.ModifiedFormPages("General").Controls("TextBox5").Value

    Str3 = Item.GetInspector.ModifiedFormPages("General").Controls("Initial Intro").Value

    Str4 = Item.GetInspector.ModifiedFormPages("General").Controls("Intro Date").Value

    Str5 = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox10").Value

    Str6 = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox3").Value

    Str7 = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox2").Value

    Str8 = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox4").Value

    Str9 = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox5").Value

    Str10 = Item.GetInspector.ModifiedFormPages("General").Controls("ContactTypeComboBox1").Value

    Str11 = Item.GetInspector.ModifiedFormPages("General").Controls("TextBox4").Value

    Str12 = Item.GetInspector.ModifiedFormPages("General").Controls("StatusComboBox1").Value

    Str13 = Item.GetInspector.ModifiedFormPages("General").Controls("TextBox20").Value

    Str14 = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox6").Value

    Str15 = Item.GetInspector.ModifiedFormPages("General").Controls("TextBox22").Value

    Str16 = Item.GetInspector.ModifiedFormPages("General").Controls("ComboBox9").Value

    Str17 = Item.GetInspector.ModifiedFormPages("General").Controls("Follow-Up ComboBox1").Value

    Str18 = Item.GetInspector.ModifiedFormPages("General").Controls("TextBox3").Value

    Str19 = Item.GetInspector.ModifiedFormPages("General").Controls("NextStepComboBox1").Value

     

    Set myItem = Application.CreateItemFromTemplate ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\Task Follow-Up.oft")

    myItem.Display

     

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox20").Value = Str

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox7").Value = Str1

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox24").Value = Str2

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox25").Value = Str3

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox26").Value = Str4

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox23").Value = Str5

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox8").Value = Str6

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox9").Value = Str7

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox10").Value = Str8

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox11").Value = Str9

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox12").Value = Str10

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox13").Value = Str11

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox14").Value = Str12

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox15").Value = Str13

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox16").Value = Str14

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox22").Value = Str15

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox21").Value = Str16

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox17").Value = Str17

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox18").Value = Str18

    myItem.GetInspector.ModifiedFormPages("P.2").Controls("TextBox19").Value = Str19

     

    myItem.Links.Add Item

    End Sub

     

    Sub Item_PropertyChange(ByVal Name)

    MsgBox "Property: " & Name

    End Sub

    Sub Item_CustomPropertyChange(ByVal Name)

    MsgBox "Field: " & Name

    Dim objField

    Set objField = Item.UserProperties(Name)

    MsgBox "Value: " & objField.Value

    End Sub

    Thursday, July 4, 2013 9:50 PM
  • Can you try one more time as I used the code you gave me etc....and it did not refresh the text boxes......the code re the link to the contact is perfect!!
    Tuesday, July 9, 2013 1:27 AM
  • I have another thought that might make this easy. Since the code I use is in script of the Contact and shows which fields of the text boxes in the Task get words from the other fields in the contact that the task is created from, how can we just adjust that code and put it in the Task script and have the code/macro recognize the fields of the contact that is assigned to the Task and just update the Task fields using another CommandButton in the Task script. The code in the script of the Contact is:

     Sub CommandButton4_Click
     Dim Str,Str1,
     Dim myItem
     
    Str = Item.GetInspector.ModifiedFormPages("General").Con trols("ComboBox7").Value
     Str1 = Item.GetInspector.ModifiedFormPages("General").Con trols("ComboBox8").Value
     Set myItem = Application.CreateItemFromTemplate ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\Task Follow-Up.oft")
     myItem.Display
     myItem.GetInspector.ModifiedFormPages("P.2").Contr ols("TextBox20").Value = Str
     myItem.GetInspector.ModifiedFormPages("P.2").Contr ols("TextBox7").Value = Str1

     myItem.Links.Add Item
     
    End Sub

    Saturday, July 20, 2013 2:13 AM