By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,662 Members | 1,779 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,662 IT Pros & Developers. It's quick & easy.

Number of items in combobox

P: n/a
Hi.

I have a combobox with a value list of 4 items. My code needs to know
the number of items in that combobox.

How can I use VBA to get the number of items in a combobox?

TIA

--
Georges
Nov 12 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Check out the properties and methods of the combo box control...
Specifically, the 'ListCount' property...
"Georges Heinesch" <vo**@void.com> wrote in message
news:40********@news.vo.lu...
Hi.

I have a combobox with a value list of 4 items. My code needs to know
the number of items in that combobox.

How can I use VBA to get the number of items in a combobox?

TIA

--
Georges

Nov 12 '05 #2

P: n/a
This works. Thanks a lot.

Is it also possible to ask which of the items is presently selected.
This would be the counterpart of teh method ItemData(), which sets the item.

TIA

Georges

--

Ruskin wrote:
Check out the properties and methods of the combo box control...
Specifically, the 'ListCount' property...
"Georges Heinesch" <vo**@void.com> wrote in message
news:40********@news.vo.lu...
Hi.

I have a combobox with a value list of 4 items. My code needs to know
the number of items in that combobox.

How can I use VBA to get the number of items in a combobox?

TIA

--
Georges

Nov 12 '05 #3

P: n/a
..ListCount
- Count of records in combo box

..ListIndex
- Index of selected record, where it starts at 0. If this is '-1' then no
record has been selected

..Text
- Text of selected record

..ItemData(.ListIndex)
- Basically the same as .Text, but you can supply the list number... NOTE:
the index number must be between 0 and ListCount minus one...

Eg:

If myCombo.ListIndex = -1 Then
MsgBox "Please select a value"
Else
MsgBox "Using Item Data: " & myCombo.ItemData(myCombo.ListIndex)
MsgBox "Same as Text: " & myCombo.Text
End If
"Georges Heinesch" <vo**@void.com> wrote in message
news:40********@news.vo.lu...
This works. Thanks a lot.

Is it also possible to ask which of the items is presently selected.
This would be the counterpart of teh method ItemData(), which sets the item.
TIA

Georges

--

Ruskin wrote:
Check out the properties and methods of the combo box control...
Specifically, the 'ListCount' property...
"Georges Heinesch" <vo**@void.com> wrote in message
news:40********@news.vo.lu...
Hi.

I have a combobox with a value list of 4 items. My code needs to know
the number of items in that combobox.

How can I use VBA to get the number of items in a combobox?

TIA

--
Georges


Nov 12 '05 #4

P: n/a
This all works perfectly now.
Thanks a lot!

Georges

--

Ruskin wrote:
..ListCount
- Count of records in combo box

..ListIndex
- Index of selected record, where it starts at 0. If this is '-1' then no
record has been selected

..Text
- Text of selected record

..ItemData(.ListIndex)
- Basically the same as .Text, but you can supply the list number... NOTE:
the index number must be between 0 and ListCount minus one...

Eg:

If myCombo.ListIndex = -1 Then
MsgBox "Please select a value"
Else
MsgBox "Using Item Data: " & myCombo.ItemData(myCombo.ListIndex)
MsgBox "Same as Text: " & myCombo.Text
End If

Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.