How can I find type of control on a form

J

John T Ingato

I would like to loop through all controls on a custom form and only process
those that are checkbox controls, or textboxes, or labels, etc.

In VBA form module, I was thinking it would be possible to do something like
this:

dim c as control

for each c in me.controls
if c.type = xlcheckbox (or whatever the correct constant should be) then
checkboxCount = checkboxCount + 1
end if
next c

The problem is that there isn't a type property for a control. Can someone
tell me how to do this. I read in help that it was possible to loop thru
the controls on worksheets by looping through the shapes collection, testing
to see if it is a control, then testing to see if it is a checkbox; however
I am interested in looping through controls on a form.
 
D

Dave Peterson

How about...

dim C as control
for each c in me.controls
if typeof c is msforms.checkbox then
'it's a checkbox
end if
next c
 
J

John T Ingato

Perfect.. Thank you Dave.

Dave Peterson said:
How about...

dim C as control
for each c in me.controls
if typeof c is msforms.checkbox then
'it's a checkbox
end if
next c
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top