Combox AddItem

Status
Not open for further replies.

eliz5387

Member
Outlook version
Email Account
Hello, I'd like to be able to load values into a combobox in outlook using the additem method with the ultimate goal of creating a second dependent combobox. While I am no longer receiving script errors, the values will not load! This is my first attempt at VB and outlook forms and I am just using an example found online. I named my combobox "ComboBox1" (properties > Value > Choose Field). I selected "view code" and added  

Private Sub UserForm_Initialize()

With ComboBox1

> AddItem "Potential client"

> AddItem "New client welcome letter"

> AddItem "Work order approval"

> AddItem "Existing client"

> AddItem "Payment overdue"

> AddItem "Invoice"

End With

End Sub

I closed out of the Script Editor window and selected "Run This Form". The form opens but the combobox has no value. What am I missing? Do I need to update the combobox properties?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
The code is for a userform in VBA, not a combobox in a custom form.

You can use an item open script to populate it at run time -

Sub Item_Open()
' Sets the name of page on the form (P.2)
Set FormPage = Item.GetInspector.ModifiedFormPages("P.2")
' Sets Control to a list box called ListBox1.
Set Control = FormPage.Controls("ComboBox1")
' Assign values to the list box.
Control.PossibleValues = "Blue;Green;Red;Yellow"

End Sub

or set the values on the control properties.
 

eliz5387

Member
Outlook version
Email Account
Thank you, Diane! That did the trick. I'm using the script editor rather than the control properties as I'd ultimately likely to create a second dependent ComboBox. My second ComboBox is named "ComboBox2". Are there any obvious changes that I should make to the code below to get this to work?

Sub Item_Open()

' Sets the name of page on the form (P.2)

Set FormPage = Item.GetInspector.ModifiedFormPages("P.2")

' Sets Control to a list box called ComboBox1.

Set Control = FormPage.Controls("ComboBox1")

' Assign values to the list box.

Control.PossibleValues = "Blue;Green;Red;Yellow"

End Sub

Sub Item_CustomPropertyChange(ByVal Name)

Select Case Name

Case "ComboBox1"

Call SetComboBox2

End Select

End Sub

Sub SetComboBox2

Set Control = FormPage.Controls("ComboBox2")

Set objInsp = Item.GetInspector

Set objPage = objInsp.ModifiedFormPages("PAF")

Set ComboBox1 = objPage.Controls("ComboBox2")

Select Case Item.UserProperties ("ComboBox1")

Case "Blue"

ComboBox2.List = Split("Sky;Ocean;Water;",",")

Case "Green"

ComboBox2.List = Split("Grass;Shamrock;",",")

Case "Red"

ComboBox2.List = Split("Strawberry;",",")

Case "Yellow"

ComboBox2.List = Split("Sun;",",")

End Select

End Sub



 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Set Control = FormPage.Controls("ComboBox2") <== i don't think you want to use the same name for both controls
Set objInsp = Item.GetInspector
Set objPage = objInsp.ModifiedFormPages("PAF")
Set ComboBox1 = objPage.Controls("ComboBox2") <== or set 1 to = 2. plus you are setting it twice.

But beyond that, i have no idea, because i can't get it to work either.

Is the use of split correct? In .net you'd use something more like this format (with a bit of code behind it)

Blue, Sky,Water;Green,Grass,Plant;Red,Strawberry,Apple;Yellow, Sun,Wheat;

I have it mostly working in the form suing the control properties but the code I've tried isn't right.
 
Status
Not open for further replies.
Top