Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
what is itemdata equivilent (if exists)
the combobox control in excel vba does not appear to support the ItemData
property. How can i accomplish the equivilent use with the combobox in excel vba? I am feeding the combobox from a database, and need to populate both the text value and the Primary Key ID number into the combobox from my query. How is this accomplished in excel vba? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
what is itemdata equivilent (if exists)
Hi
Based on my research, the ItemData is used to get the data based on the index. e.g. Label1.Caption = "Empoyee #" & _ CStr(Combo1.ItemData(Combo1.ListIndex)) VBA controls has different implement with the VB controls. The VBA Controls ComboBox did not have the ItemData property. We will find that we will add two columns into the combobox, so that when we change the BoundColumn, the ComboBox1.Value will change to different column. I think you may try to run the code below. Private Sub OptionButton1_Click() ComboBox1.BoundColumn = 0 Label1.Caption = ComboBox1.Value End Sub Private Sub OptionButton2_Click() ComboBox1.BoundColumn = 1 Label1.Caption = ComboBox1.Value End Sub Private Sub OptionButton3_Click() ComboBox1.BoundColumn = 2 Label1.Caption = ComboBox1.Value End Sub Private Sub ComboBox1_Click() Label1.Caption = ComboBox1.Value End Sub Private Sub UserForm_Initialize() ComboBox1.ColumnCount = 2 ComboBox1.AddItem "Item 1, Column 1" ComboBox1.List(0, 1) = "Item 1, Column 2" ComboBox1.AddItem "Item 2, Column 1" ComboBox1.List(1, 1) = "Item 2, Column 2" ComboBox1.Value = "Item 1, Column 1" OptionButton1.Caption = "List Index" OptionButton2.Caption = "Column 1" OptionButton3.Caption = "Column 2" OptionButton2.Value = True End Sub Also if you are using ADO to access to Database, then I assme you are using Recordset. So we can use recordset's filter function to filter the PK, so that we now have one record, because the PK is unique. Now we can retrieve the columnx to get the data we want from the Recordset. Best regards, Peter Huang Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Input Masks or equivilent | Excel Worksheet Functions | |||
File Exists | Excel Discussion (Misc queries) | |||
keyboard equivilent of the right-click | Excel Worksheet Functions | |||
Exists? | Excel Programming | |||
Combobox ItemData | Excel Programming |