Dropdown data list in view

S

SubSeaGuy

I have added a custom field in my task form. Data is selected via a dropdown
menu. I have tested it and the data is retained with no problems. I have
also included my custom field in a list view. When I try to enter data in
this field via in-cell editing, my dropdown is not available. I can enter
data and it is retained but I would like the same dropdown menu available for
in-cell editing in the list view as is available on the form. Can this be
done and if so, how would I go about doing it?
 
S

Sue Mosher [MVP-Outlook]

No, that cannot be done. Outlook does not support custom drop-down lists in folder views.
 
S

SubSeaGuy

Thanks Sue. How about a drop down in the toolbar to select from the list?
Any guidance on the best way to do that?
 
S

Sue Mosher [MVP-Outlook]

This VBA code sample creates a new button on the Standard toolbar when Outlook starts up and runs code when the button is clicked to update a custom property with the value the user selects from a dropdown list:

Dim WithEvents objCBC As Office.CommandBarComboBox

Private Sub Application_Startup()
Dim objExpl As Outlook.Explorer
Dim objCB As Office.CommandBar
On Error Resume Next
Set objExpl = Application.ActiveExplorer
Set objCB = objExpl.CommandBars("Standard")
Set objCBC = objCB.Controls.Add(Type:=msoControlComboBox, _
Temporary:=True)

' adapted from Help file
With objCBC
.AddItem "Get Stock Quote", 1
.AddItem "View Chart", 2
.AddItem "View Fundamentals", 3
.AddItem "View News", 4
.DescriptionText = "View Data For Stock"
.text = "Select option here"
.Width = 200
.Style = msoComboNormal
End With
Set objCB = Nothing
Set objExpl = Nothing
End Sub

Private Sub objCBC_Change(ByVal Ctrl As Office.CommandBarComboBox)
Dim objExpl As Outlook.Explorer
Dim objTask As Outlook.taskItem
Dim objProp As Outlook.UserProperty
Dim strPropName As String
On Error Resume Next
' set the name of the custom property here
strPropName = "My Custom Property Name"
Set objExpl = Application.ActiveExplorer
For Each objTask In objExpl.Selection
Set objProp = objTask.UserProperties(strPropName)
' if the property doesn't exist, create it
If objProp Is Nothing Then
Set objProp = _
objTask.UserProperties.Add(Name:=strPropName, _
Type:=olText)
End If
objProp.Value = objCBC.text
objTask.Save
Next
objCBC.text = "Select option here"
Set objProp = Nothing
Set objExpl = Nothing
Set objTask = Nothing
End Sub

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
S

SubSeaGuy

Thanks a lot Sue. Does this run from within the form or from an Outlook VBA
module?
 
S

SubSeaGuy

Sue.. I did see that. I am VERY new at this. I am sometimes still not clear
about where the code goes. From your response, I assume I would place this
code in the same place where I put macro's. Correct?
 
S

Sue Mosher [MVP-Outlook]

Yes, macros are one type of VBA procedure. Event handlers, such as that to handle the Click event of a CommandBarButton, are another type of VBA procedure. The sample code I posted needs to go in the built-in ThisOutlookSession module.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
S

SubSeaGuy

Thanks Sue. I have no idea how you provide so much feedback to so many
people. You're awsome.
 
S

SubSeaGuy

OK.. the menu bar is working fine. When I open a new task though, the
selection is not available. I have tried to locate it in the standard menu
bar but I guess it is not retained there. I have tried using the script
within the form but get errors. Any suggestions?
 
S

Sue Mosher [MVP-Outlook]

None of the code I posted has anything to do with VBScript behind a custom form or with an item opened in its own custom form window. The whole point of this toolbar button is to provide functionality in a table view for a folder that is similar to what the control on your custom form does. In other words, the toolbar button is designed to be there only in the folder window. If you want something other functionality, please provide a description.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
S

SubSeaGuy

I would be looking for the same functionality with an open task form
(dropdown menu) to fill a user-defined field within the form.
 
S

Sue Mosher [MVP-Outlook]

The event to use to add a toolbar to an Inspector window is Inspectors.NewInspector. In the Outlook VBA code below, note how the common operations of filling the combo box and processing a task are broken out into separate procedures that can be called for the combo box on either type of window:

' place all code in the built-in ThisOutlookSession module in Outlook VBA
Option Explicit
Dim WithEvents objCBC_E As Office.CommandBarComboBox
Dim WithEvents objCBC_I As Office.CommandBarComboBox
Dim WithEvents colInsp As Outlook.Inspectors

Private Sub Application_Startup()
Dim objExpl As Outlook.Explorer
Dim objCB As Office.CommandBar
On Error Resume Next
Set colInsp = Application.Inspectors
Set objExpl = Application.ActiveExplorer
Set objCB = objExpl.CommandBars("Standard")
Set objCBC_E = objCB.Controls.Add(Type:=msoControlComboBox, _
Temporary:=True)
Call FillCombo(objCBC_E)
Set objCB = Nothing
Set objExpl = Nothing
End Sub

Private Sub colInsp_NewInspector(ByVal Inspector As Inspector)
Dim objCB As Office.CommandBar
On Error Resume Next
Set objCB = Inspector.CommandBars("Standard")
Set objCBC_I = objCB.FindControl(msoControlComboBox, , "MyCombo")
If objCBC_I Is Nothing Then
Set objCBC_I = objCB.Controls.Add(Type:=msoControlComboBox, _
Temporary:=True)
Call FillCombo(objCBC_I)
End If
Set objCB = Nothing
End Sub

Private Sub objCBC_E_Change(ByVal Ctrl As Office.CommandBarComboBox)
Dim objExpl As Outlook.Explorer
Dim objTask As Outlook.taskItem
Dim objProp As Outlook.UserProperty
On Error Resume Next
Set objExpl = Application.ActiveExplorer
For Each objTask In objExpl.Selection
Call UpdateTask(objTask, objCBC_E.text)
Next
objCBC_E.text = "Select option here"
Set objProp = Nothing
Set objExpl = Nothing
Set objTask = Nothing
End Sub

Private Sub objCBC_I_Change(ByVal Ctrl As Office.CommandBarComboBox)
Dim objTask As Outlook.taskItem
Dim objProp As Outlook.UserProperty
On Error Resume Next
Set objTask = Application.ActiveInspector.CurrentItem
Call UpdateTask(objTask, objCBC_I.text)
objCBC_I.text = "Select option here"
Set objProp = Nothing
Set objTask = Nothing
End Sub

Sub FillCombo(cbc As Office.CommandBarControl)
' adapted from Help file
With cbc
.AddItem "Get Stock Quote", 1
.AddItem "View Chart", 2
.AddItem "View Fundamentals", 3
.AddItem "View News", 4
.DescriptionText = "View Data For Stock"
.text = "Select option here"
.Tag = "MyCombo"
.Width = 200
.Style = msoComboNormal
End With
End Sub

Sub UpdateTask(task As Outlook.taskItem, choice As String)
Dim objProp As Outlook.UserProperty
Dim strPropName As String
' set the name of the custom property here
strPropName = "My Custom Property Name"
Set objProp = task.UserProperties(strPropName)
' if the property doesn't exist, create it
If objProp Is Nothing Then
Set objProp = _
task.UserProperties.Add(Name:=strPropName, _
Type:=olText)
End If
objProp.Value = choice
task.Save
Set objProp = Nothing
End Sub

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top