Finding a control's type

R

Ron Lounsbury

I have a form that has a series of check boxes, each named chkErr1, chkErr2,
chkErr3, etc. I want a command button to loop through each of the check
boxes and perform an action if the checkbox is checked. I tried the
following code:

Dim thisCtl As Control

For Each thisCtl In Me.Controls
if thisCtl.type = "Checkbox" then
if thisCtl.value = 1 then
ProcessChecked
end if
end if
Next

however, the .type is not a recognized property or method for the Control
type. Can anyone tell me the right way to get only the checkboxes on the
form? I can check the name to see if it starts with "chk", but that seems
to be kludgy.

TIA
Ron Lounsbury
 
J

Jan Hyde

"Ron Lounsbury" <rlounsbury AT Progeny DOT net>'s wild
thoughts were released on Wed, 10 Sep 2003 10:18:13 -0400
bearing the following fruit:
I have a form that has a series of check boxes, each named chkErr1, chkErr2,
chkErr3, etc. I want a command button to loop through each of the check
boxes and perform an action if the checkbox is checked. I tried the
following code:


Check out TypeOf and TypeName

J
 
R

Rubén Vigón

Dim c As Control
For Each c In Controls
If TypeOf c Is CheckBox Then...
Next c

Regards,

Rubén Vigón
Microsoft MVP Visual Basic
 
R

Ron Lounsbury

Jan
Thanks. I'll give it a try.

Ron Lounsbury

Jan Hyde said:
"Ron Lounsbury" <rlounsbury AT Progeny DOT net>'s wild
thoughts were released on Wed, 10 Sep 2003 10:18:13 -0400
bearing the following fruit:



Check out TypeOf and TypeName

J
 
V

Van T. Dinh

****Untested****
Dim thisCtl As Access.Control
For Each thisCtl In Me.Controls
if thisCtl.ControlType = acCheckbox then
if thisCtl.value <> 0 then
ProcessChecked
end if
end if
Next
****

HTH
Van T. Dinh
MVP (Access)
 

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