Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 711
  • Last Modified:

Outlook custom form - two pairs of dependent ComboBoxes

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
etdowdle
Asked:
etdowdle
  • 4
  • 3
1 Solution
 
David LeeCommented:
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
 
etdowdleAuthor Commented:
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
 
David LeeCommented:
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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
etdowdleAuthor Commented:
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
 
David LeeCommented:
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
 
etdowdleAuthor Commented:
Excellent! I did change "Action" on row 22 to "Action2" to eliminate any interdependence between the two sets of comboboxes.

Thank you!!!
0
 
David LeeCommented:
You're welcome. Glad I could help out.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now