none
Outlook custom forms - Please help! RRS feed

  • Question

  • Hi all,

    I have been pulling my hair out trying to find solutions to the following as related to Outlook custom forms, and I have to say that I really am learning to hate VB script :)  Thank you in advance for the help, and I'll mail you a beer for your trouble!

    1) Popluate a combobox with existing values from the bound field.  In this case the it is a user-defined field "cProject", and I would like the user to enter new projects or have to select from an existing list of projects

    2) Shade the reminder date and reminder time controls is the reminder checkbox is unchecked

    3) Create a task whenever I flag an e-mail for follow-up.  Outlook would then create a copy of the e-mail to a folder named "Tasks" and create an outlook EntryID link in the new task.  Then send the e-mail I have flagged.  I have chunks of code for all three below

    #1) 

    Sub PopulateProjectComboBox()

       Dim FullArray()

       ' Sets the name of page on the form (P.2)
       Set FormPage = Item.GetInspector.ModifiedFormPages("Task New")

       ' Sets Control to a list box called ListBox1.
       Set Control = FormPage.Controls("OlkComboBoxProject")

       ' Get the default Contacts folder
       Set ConFolder = Application.Session.GetDefaultFolder(13)

       ' Get the items in the folder
       Set ConItems = ConFolder.Items

       Set objProject = Item.UserProperties("Project")
      

       ' Resize array to handle total number of item in the folder
       ReDim FullArray(NumItems-1,2)

       ' Loop through all of the items in the Contacts folder,
       ' filling the array with sample data and keeping track
       ' of the number of contacts found.
       NumContacts = 0
       For I = 1 to NumItems
          Set itm = ConItems(I)
          If Left(itm.MessageClass, 11) = "IPM.Task" Then
             NumContacts = NumContacts + 1
             FullArray(NumContacts-1,1)= itm.cProject
          End If
       Next

       ' Set the control to handle 2 data columns
       Control.ColumnCount = -1

       If NumItems = NumContacts Then
          ' They are all contacts, so use the FullArray
          Control.List() = FullArray
       Else
          ' There's some distribution lists, so use the smaller
          ' ConArray to eliminate extra blank values in the list box
          Dim ConArray()
          ReDim ConArray(NumContacts-1,2)
          For I = 0 to NumContacts - 1
             ConArray(I,1) = FullArray(I,1)
          Next
          Control.List() = ConArray
       End If

    End Sub                           

    #2)

    Sub ShadeControlWhenChecked()

    Sets the name of page on the form (P.4)
    Set objInsp = Item.GetInspector.ModifiedFormPages("Task New")
    Set objChkBox = Item.UserProperties("Reminder")
    Set objRemindDate = objInsp.Controls("OlkDateControlReminderDate")
    Set objRemindTime = objInsp.Controls("OlkTimeControlReminderTime")

    Set objInspector = Item.GetInspector.ModifiedFormPages("Task New")
    Set objChkBox = Item.UserProperties("Reminder")
    Set objRemindDate = objInspector.Controls("OlkDateControlReminderDate")

       If objChkBox.Value = False Then
         objRemindDate.BackColor = vbred
         objRemindDate.ForeColor = vbGrey
       End If

       If objChkBox.Value = True Then
         objRemindDate.BackColor = olColorWhite
         objRemindDate.ForeColor = olColorBlack
         objRemindTime.BackColor = olColorWhite
         objRemindTime.ForeColor = olColorBlack
       End If


    End Sub                           

    #3)    

    Dim myItem As Outlook.MailItem
        Dim olTsk As Outlook.TaskItem
        
        Set myItem = ActiveExplorer.Selection.Item(1)
        Set olTsk = CreateItem(olTaskItem)
        
        With olTsk
            .Subject = myItem.Subject
            .StartDate = Now()
             '[paste link to myItem here]
            .Body = .Body & vbCrLf & "url:outlook:" & myItem.EntryID & vbCrLf
        End With
        olTsk.Display
        
        Set olTsk = Nothing
        Set myItem = Nothing
    End Sub

    Wednesday, May 2, 2012 12:54 PM

Answers

  • You say the code for #'s 1 & 2 isn't running. Are you actually calling those Subs from anywhere?
     
    For #3 I'd call the code when the PropertyChange() event fires on the item. You'd need to instantiate an instance of the item as a MailItem when an item was opened (Inspectors.NewInspector event) or when it was selected (ActiveExplorer.SelectionChange event). You'd then add an event handler for PropertyChange() for the item.
     
    That would also be a good place to call the sub for #2, if you aren't calling it from anywhere.

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    Reminder Manager, Extended Reminders, Attachment Options
    http://www.slovaktech.com/products.htm
     
     
    "Dusty458" <=?utf-8?B?RHVzdHk0NTg=?=> wrote in message news:88331d8a-582c-49f5-9169-c9e876a4f4be...

    Hi Ken,

    Thanks for the replies to my posts.  I am running Outlook 2010.  For #1 and #2 the code is fine.  The problem is that it does not run - the combo box is not populated and the shading sub does not run is the "reminder" box is checked or unchecked.

    As for #3  I'm not sure how to take the code I have and add the functionality I've described.

    Thanks for any help!


    Ken Slovak MVP - Outlook
    Thursday, May 3, 2012 3:41 PM
    Moderator

All replies

  • What version of Outlook? Always provide at least that information.
     
    What is not working with your code? Be specific for each case so we don't have to guess.

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    Reminder Manager, Extended Reminders, Attachment Options
    http://www.slovaktech.com/products.htm
     
     
    "Dusty458" <=?utf-8?B?RHVzdHk0NTg=?=> wrote in message news:5fa9e5fa-525d-4290-a9fb-a298fd0e46de...

    Hi all,

    I have been pulling my hair out trying to find solutions to the following as related to Outlook custom forms, and I have to say that I really am learning to hate VB script :)  Thank you in advance for the help, and I'll mail you a beer for your trouble!

    1) Popluate a combobox with existing values from the bound field.  In this case the it is a user-defined field "cProject", and I would like the user to enter new projects or have to select from an existing list of projects

    2) Shade the reminder date and reminder time controls is the reminder checkbox is unchecked

    3) Create a task whenever I flag an e-mail for follow-up.  Outlook would then create a copy of the e-mail to a folder named "Tasks" and create an outlook EntryID link in the new task.  Then send the e-mail I have flagged.  I have chunks of code for all three below

    #1) 

    Sub PopulateProjectComboBox()

       Dim FullArray()

       ' Sets the name of page on the form (P.2)
       Set FormPage = Item.GetInspector.ModifiedFormPages("Task New")

       ' Sets Control to a list box called ListBox1.
       Set Control = FormPage.Controls("OlkComboBoxProject")

       ' Get the default Contacts folder
       Set ConFolder = Application.Session.GetDefaultFolder(13)

       ' Get the items in the folder
       Set ConItems = ConFolder.Items

       Set objProject = Item.UserProperties("Project")
      

       ' Resize array to handle total number of item in the folder
       ReDim FullArray(NumItems-1,2)

       ' Loop through all of the items in the Contacts folder,
       ' filling the array with sample data and keeping track
       ' of the number of contacts found.
       NumContacts = 0
       For I = 1 to NumItems
          Set itm = ConItems(I)
          If Left(itm.MessageClass, 11) = "IPM.Task" Then
             NumContacts = NumContacts + 1
             FullArray(NumContacts-1,1)= itm.cProject
          End If
       Next

       ' Set the control to handle 2 data columns
       Control.ColumnCount = -1

       If NumItems = NumContacts Then
          ' They are all contacts, so use the FullArray
          Control.List() = FullArray
       Else
          ' There's some distribution lists, so use the smaller
          ' ConArray to eliminate extra blank values in the list box
          Dim ConArray()
          ReDim ConArray(NumContacts-1,2)
          For I = 0 to NumContacts - 1
             ConArray(I,1) = FullArray(I,1)
          Next
          Control.List() = ConArray
       End If

    End Sub                           

    #2)

    Sub ShadeControlWhenChecked()

    Sets the name of page on the form (P.4)
    Set objInsp = Item.GetInspector.ModifiedFormPages("Task New")
    Set objChkBox = Item.UserProperties("Reminder")
    Set objRemindDate = objInsp.Controls("OlkDateControlReminderDate")
    Set objRemindTime = objInsp.Controls("OlkTimeControlReminderTime")

    Set objInspector = Item.GetInspector.ModifiedFormPages("Task New")
    Set objChkBox = Item.UserProperties("Reminder")
    Set objRemindDate = objInspector.Controls("OlkDateControlReminderDate")

       If objChkBox.Value = False Then
         objRemindDate.BackColor = vbred
         objRemindDate.ForeColor = vbGrey
       End If

       If objChkBox.Value = True Then
         objRemindDate.BackColor = olColorWhite
         objRemindDate.ForeColor = olColorBlack
         objRemindTime.BackColor = olColorWhite
         objRemindTime.ForeColor = olColorBlack
       End If


    End Sub                           

    #3)    

    Dim myItem As Outlook.MailItem
        Dim olTsk As Outlook.TaskItem
        
        Set myItem = ActiveExplorer.Selection.Item(1)
        Set olTsk = CreateItem(olTaskItem)
        
        With olTsk
            .Subject = myItem.Subject
            ..StartDate = Now()
             '[paste link to myItem here]
            .Body = ..Body & vbCrLf & "url:outlook:" & myItem.EntryID & vbCrLf
        End With
        olTsk.Display
        
        Set olTsk = Nothing
        Set myItem = Nothing
    End Sub


    Ken Slovak MVP - Outlook
    Wednesday, May 2, 2012 2:38 PM
    Moderator
  • Hi Ken,

    Thanks for the replies to my posts.  I am running Outlook 2010.  For #1 and #2 the code is fine.  The problem is that it does not run - the combo box is not populated and the shading sub does not run is the "reminder" box is checked or unchecked.

    As for #3  I'm not sure how to take the code I have and add the functionality I've described.

    Thanks for any help!

    Thursday, May 3, 2012 12:08 AM
  • You say the code for #'s 1 & 2 isn't running. Are you actually calling those Subs from anywhere?
     
    For #3 I'd call the code when the PropertyChange() event fires on the item. You'd need to instantiate an instance of the item as a MailItem when an item was opened (Inspectors.NewInspector event) or when it was selected (ActiveExplorer.SelectionChange event). You'd then add an event handler for PropertyChange() for the item.
     
    That would also be a good place to call the sub for #2, if you aren't calling it from anywhere.

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    Reminder Manager, Extended Reminders, Attachment Options
    http://www.slovaktech.com/products.htm
     
     
    "Dusty458" <=?utf-8?B?RHVzdHk0NTg=?=> wrote in message news:88331d8a-582c-49f5-9169-c9e876a4f4be...

    Hi Ken,

    Thanks for the replies to my posts.  I am running Outlook 2010.  For #1 and #2 the code is fine.  The problem is that it does not run - the combo box is not populated and the shading sub does not run is the "reminder" box is checked or unchecked.

    As for #3  I'm not sure how to take the code I have and add the functionality I've described.

    Thanks for any help!


    Ken Slovak MVP - Outlook
    Thursday, May 3, 2012 3:41 PM
    Moderator