Solved

Outlook custom form - two pairs of dependent ComboBoxes

Posted on 2014-01-22
7
595 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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
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…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now