List All Controls On Form

G

Guest

OK, this should be a fairly simple question, but I'm stuck. Quite simply, I
want to generate a list containing the name of each control on a form. I was
thinking something like

Public Sub EnumerateControls()

Dim ctl As Control

For Each ctl In Me.Controls
Debug.Print ctl.Name
Next

End Sub

Unfortunately, Name doesnt seem to be a property of Control objects. Any
thoughts? And yes, this is just a stepping stone to greater uses, but it's
good to start simple. Thanks,

Matt Martin
 
R

RuralGuy

=?Utf-8?B?TWFydGluTUNV?= said:
OK, this should be a fairly simple question, but I'm stuck. Quite
simply, I want to generate a list containing the name of each control
on a form. I was thinking something like

Public Sub EnumerateControls()

Dim ctl As Control

For Each ctl In Me.Controls
Debug.Print ctl.Name
Next

End Sub

Unfortunately, Name doesnt seem to be a property of Control objects.
Any thoughts? And yes, this is just a stepping stone to greater uses,
but it's good to start simple. Thanks,

Matt Martin

Hi Matt,

Have you tried here:

http://www.mvps.org/access/forms/frm0004.htm
Forms: Enumerate all controls on a form

By the way it is rarely necessary to post to more than one group. At
least you did it the right way so we can all see the other groups.

HTH
 
D

Dirk Goldgar

MartinMCU said:
OK, this should be a fairly simple question, but I'm stuck. Quite
simply, I want to generate a list containing the name of each control
on a form. I was thinking something like

Public Sub EnumerateControls()

Dim ctl As Control

For Each ctl In Me.Controls
Debug.Print ctl.Name
Next

End Sub

Unfortunately, Name doesnt seem to be a property of Control objects.
Any thoughts? And yes, this is just a stepping stone to greater uses,
but it's good to start simple. Thanks,

Matt Martin

Don't worry -- controls do have a Name property, and your code works
fine.
 

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