ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Combobox ItemData (https://www.excelbanter.com/excel-programming/296479-combobox-itemdata.html)

BananaQuaalude[_2_]

Combobox ItemData
 
Do comboboxes in Excel have an ItemData? I'm populating a combobox fro
a database and need to tie the record's UID to what's displayed in th
box.

Do I have to use multiple columns in the combobox to do this? And jus
hide that column maybe?

I know VBA pretty well, just have never used it in Excel before.

Thanks

--
Message posted from http://www.ExcelForum.com


Rob Bovey

Combobox ItemData
 
Do comboboxes in Excel have an ItemData? I'm populating a combobox from
a database and need to tie the record's UID to what's displayed in the
box.


No. Unfortunately MSForms combo box controls lack this feature.

Do I have to use multiple columns in the combobox to do this? And just
hide that column maybe?


That's the easiest way to accomplish the same thing.

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *



BananaQuaalude[_4_]

Combobox ItemData
 
Thank you, Rob.

For some reason I didn't get notified by email when you posted this, s
I didn't see it until I checked the post just now.

So I'm taking the route of using multiple columns. When looping throug
a recordset to populate the combobox, how do I refer to a specifi
column?

Here's what I tried:

UserForm1.cboAccount.ColumnCount = 2
UserForm1.cboAccount.ColumnWidths = "2,0"

Do Until rs.EOF
UserForm1.cboAccount.column(0) = rs!acct_name
UserForm1.cboAccount.column(1) = rs!acct_id
'UserForm1.cboAccount.ListIndex = rs!acct_id
rs.MoveNext
Loop

But I think that's only for loading arrays. Is there a simple way t
load the two columns for each line?

Thanks

--
Message posted from http://www.ExcelForum.com


BananaQuaalude[_3_]

Combobox ItemData
 
Okay- disregard that last question. I figured it out:

Do Until rs.EOF
With UserForm1.cboAccount
.AddItem rs!acct_name
.List(.ListCount - 1, 1) = rs!acct_id
End With
rs.MoveNext
Loop

Thanks

--
Message posted from http://www.ExcelForum.com


BananaQuaalude[_5_]

Combobox ItemData
 
Okay- disregard that last question. I figured it out:

Do Until rs.EOF
With UserForm1.cboAccount
.AddItem rs!acct_name
.List(.ListCount - 1, 1) = rs!acct_id
End With
rs.MoveNext
Loop

Thanks

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 02:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com