PC Review


Reply
Thread Tools Rate Thread

How can I find type of control on a form

 
 
John T Ingato
Guest
Posts: n/a
 
      5th Nov 2006
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.


 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      5th Nov 2006
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



John T Ingato wrote:
>
> 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.


--

Dave Peterson
 
Reply With Quote
 
John T Ingato
Guest
Posts: n/a
 
      5th Nov 2006
Perfect.. Thank you Dave.

"Dave Peterson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>
>
> John T Ingato wrote:
>>
>> 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.

>
> --
>
> Dave Peterson



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find control type in DataGrid Doug Bell Microsoft VB .NET 1 15th Mar 2007 10:45 AM
How can I find type of control on a form John T Ingato Microsoft Excel Programming 1 5th Nov 2006 10:09 PM
How can I find the type of control through reflection Shahzad Atta Microsoft Dot NET 2 5th Jan 2005 10:17 AM
Find out type of a control Alberto Microsoft C# .NET 4 23rd Oct 2004 02:41 AM
Cannot find type of user control? Jacob Avlund Microsoft ASP .NET 0 23rd Sep 2004 11:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:16 PM.