Solved

Outlook custom form - two pairs of dependent ComboBoxes

Posted on 2014-01-22
7
600 Views
Last Modified: 2014-01-24
Hello - I'm hoping this is an easy fix. I've set up two pairs of  dependent ComboBoxes using this method:
http://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/Q_26924676.html

I used essentially the same code twice for the two pairs of ComboBoxes. When I added the second pair with code the first stopped functioning (IE. the dependent ComboBox no longer pulls a value). I'm guessing I need to update the transition between the two sets of code.

Any suggestions?

Sub Item_CustomPropertyChange(actionreason)
Dim objPage, objControl
Set objPage = Item.GetInspector.ModifiedFormPages("P.2")
Select Case actionreason
Case "Action"
ClearCombobox objControl
Set objControl = objPage.Controls("cboReason")
ClearCombobox objControl
 Select Case Item.UserProperties("Action")
Case "MA"
objControl.AddItem "Boston"
objControl.AddItem "Worcester"
objControl.AddItem "CA"
objControl.AddItem "San Diego"
objControl.AddItem "San Francisco"
Case "FL"
objControl.AddItem "Orlando"
End Select
Case "Reason"
ClearCombobox objControl
Select Case Item.UserProperties("Reason")
End Select            
End Select
End Sub

Sub ClearCombobox(objCombo)
Dim intIndex
On Error Resume Next
With objCombo
For intIndex = .ListCount To 0 Step -1
.RemoveItem intIndex
Next
.SelText = ""
End With
On Error Goto 0
End Sub

Sub Item_CustomPropertyChange(actionreason2)
Dim objPage, objControl
Set objPage = Item.GetInspector.ModifiedFormPages("P.2")
Select Case actionreason2
Case "Action2"
ClearCombobox objControl
Set objControl = objPage.Controls("cboReason2")
ClearCombobox objControl
Select Case Item.UserProperties("Action2")
Case "MA"
objControl.AddItem "Boston"
objControl.AddItem "Worcester"
objControl.AddItem "CA"
objControl.AddItem "San Diego"
objControl.AddItem "San Francisco"
Case "FL"
objControl.AddItem "Orlando"
End Select
Case "Reason"
ClearCombobox objControl
Select Case Item.UserProperties("Reason2")
End Select            
End Select
End Sub

Sub ClearCombobox(objCombo)
Dim intIndex
On Error Resume Next
With objCombo
For intIndex = .ListCount To 0 Step -1
.RemoveItem intIndex
Next
.SelText = ""
End With
On Error Goto 0
End Sub
        

Open in new window

0
Comment
Question by:etdowdle
  • 4
  • 3
7 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 39801147
Hi, etdowdle.

The error is a result of having duplicate functions with the same name.  Only one function with a given name is allowed.  First, there's no need for two ClearComboBox functions.  Second, you need to combine the two CustomPropertyChange functions into a single function.  Inside of that function you need to handle the different custom property names.  Something like this

Sub Item_CustomPropertyChange(strName)
    Dim objPage, objControl
    Select Case strName
        Case "actionreason"
            Set objPage = Item.GetInspector.ModifiedFormPages("P.2")
            Select Case actionreason
                Case "Action"
                    Set objControl = objPage.Controls("cboReason")
                    ClearCombobox objControl
                    Select Case Item.UserProperties("Action")
                        Case "MA"
                            objControl.AddItem "Boston"
                            objControl.AddItem "Worcester"
                            objControl.AddItem "CA"
                            objControl.AddItem "San Diego"
                            objControl.AddItem "San Francisco"
                        Case "FL"
                            objControl.AddItem "Orlando"
                    End Select
                Case "Reason"
                    ClearCombobox objControl
                    Select Case Item.UserProperties("Reason")
                    End Select            
            End Select
        Case "actionreason2"
            Set objPage = Item.GetInspector.ModifiedFormPages("P.2")
            Select Case actionreason2
                Case "Action2"
                    Set objControl = objPage.Controls("cboReason2")
                    ClearCombobox objControl
                    Select Case Item.UserProperties("Action2")
                        Case "MA"
                            objControl.AddItem "Boston"
                            objControl.AddItem "Worcester"
                            objControl.AddItem "CA"
                            objControl.AddItem "San Diego"
                            objControl.AddItem "San Francisco"
                        Case "FL"
                            objControl.AddItem "Orlando"
                    End Select
                Case "Reason"
                    ClearCombobox objControl
                    Select Case Item.UserProperties("Reason2")
                    End Select            
            End Select
    End Select
End Sub

Sub ClearCombobox(objCombo)
    Dim intIndex
    On Error Resume Next
    With objCombo
        For intIndex = .ListCount To 0 Step -1
            .RemoveItem intIndex
        Next
        .SelText = ""
    End With
    On Error Goto 0
End Sub

Open in new window

0
 

Author Comment

by:etdowdle
ID: 39801446
Hi BlueDevilFan,

Thanks for your response. Unfortunately, I am now unable to pull values from either combobox. I apologize as I am just learning vbscript/outlook custom forms.
Let me provide you with some additional details.

In this example I have:
combobox1 - Name: cboAction  Value: Action
combobox2 - Name: cboReason  Value: Reason
combobox3 - Name: cboAction2  Value: Action2
combobox4 - Name: cboReason2  Value: Reason2

cboAction and cboAction2 have possible values "MA; CA; FL" on the value tab. An error on the initial code I sent - it should have read 'Case "CA"' rather than ' objControl.AddItem "CA"'

Do you have any additional suggestions? Thank you
0
 
LVL 76

Expert Comment

by:David Lee
ID: 39801556
Please describe how the comboboxes work together?  For example, if the user chooses a certain value from cboAction, then a given set of values are loaded into cboReason.  Also, what are the names of the properties the comboboxes are bound to?
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:etdowdle
ID: 39801681
In this example -
The user should be able to select a state from cboAction (let's say "MA") and then a city from cboReason (if MA, then "Boston" or "Worcester").
In a separate section of the form, the user should then be able to select another state from cboAction2 (they can select "MA" again) and then a city from cboReason2 (if MA, then "Boston" or "Worcester" again).

I listed the properties as values in my last comment.

combobox1 - Name: cboAction  Property: Action
combobox2 - Name: cboReason  Property: Reason
combobox3 - Name: cboAction2  Property: Action2
combobox4 - Name: cboReason2  Property: Reason2
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 39806127
I've revised the code.  Please give this version a try and let me know if that fixes the problem.

Sub Item_CustomPropertyChange(strName)
    Dim objPage, objControl
    Select Case LCase(strName)
        Case "action"
            Set objPage = Item.GetInspector.ModifiedFormPages("P.2")
            Set objControl = objPage.Controls("cboReason")
            ClearCombobox objControl
            Select Case Item.UserProperties("Action")
                Case "MA"
                    objControl.AddItem "Boston"
                    objControl.AddItem "Worcester"
                Case "CA"
                    objControl.AddItem "San Diego"
                    objControl.AddItem "San Francisco"
                Case "FL"
                    objControl.AddItem "Orlando"         
            End Select
        Case "action2"
            Set objPage = Item.GetInspector.ModifiedFormPages("P.2")
            Set objControl = objPage.Controls("cboReason2")
            ClearCombobox objControl
            Select Case Item.UserProperties("Action")
                Case "MA"
                    objControl.AddItem "Boston"
                    objControl.AddItem "Worcester"
                Case "CA"
                    objControl.AddItem "San Diego"
                    objControl.AddItem "San Francisco"
                Case "FL"
                    objControl.AddItem "Orlando"        
            End Select
    End Select
End Sub

Sub ClearCombobox(objCombo)
    Dim intIndex
    On Error Resume Next
    With objCombo
        For intIndex = .ListCount To 0 Step -1
            .RemoveItem intIndex
        Next
        .SelText = ""
    End With
    On Error Goto 0
End Sub

Open in new window

0
 

Author Comment

by:etdowdle
ID: 39806904
Excellent! I did change "Action" on row 22 to "Action2" to eliminate any interdependence between the two sets of comboboxes.

Thank you!!!
0
 
LVL 76

Expert Comment

by:David Lee
ID: 39807154
You're welcome. Glad I could help out.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question