Solved

Outlook custom form - two pairs of dependent ComboBoxes

Posted on 2014-01-22
7
591 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Join & Write a Comment

Get an idea of what you should include in an email disclaimer with these Top 5 email disclaimer tips.
Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
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…

758 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

19 Experts available now in Live!

Get 1:1 Help Now