472,131 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,131 software developers and data experts.

Number of items in combobox

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
4 25880
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
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
..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
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.

Similar topics

4 posts views Thread by Georges Heinesch | last post: by
19 posts views Thread by hao | last post: by
reply views Thread by bcreighton | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.