Accessing All Same Controls on a Form at Once

M

Mr. JYC

Hello,

I know this must be done programmatically but how do you access same
controls on a form all at once and obtain specific information about each
such as the data it contains, the name of the control, and all the properties
that could be normally accessed in a control one at a time?

I know this has some thing to do with the Controls class, Control class, and
enumerating with For Each...Next. I have not been able to successfully
implement the code for this.

Could someone please help me with this?
 
N

Noëlla Gabriël

Hi,

not that difficult; in the following example the code scans every control on
the current form, and those that have the tag property = value "Lock" , are
locked

Dim ctl As control

For Each ctl In Me.Controls
If ctl.Tag = "Lock" Then
ctl.Locked = true
'Debug.Print ctl.Name & " " & ctl.Tag
End If
Next ctl
 
D

Douglas J. Steele

Depends on the property. For most of them, you'd use ctl.NameOfProperty. For
other properties, you might need to use ctl.Properties("NameOfProperty")
 

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