Click here to Skip to main content
15,887,917 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
iam new to access
and may be my question is not right
when i want to get all controls names in specific form i am using the following
for each ctrl in me.controls
and i add ctrl.name to a table to get all controls names
but if have a lot of forms like 200 forms i have to open all the forms to get all controls names in the current project
is there any design file that contains controls names
i mean with out the need to get these names dynamically at run time
Posted
Updated 10-Sep-15 1:34am
v2

Here is how:
VB
Public Sub ListFormControls()

    Dim obj As Object
    Dim frm As Form
    Dim ctl As Control

    For Each obj In Application.CurrentProject.AllForms
        DoCmd.OpenForm obj.Name, acDesign, , , , acHidden
        Set frm = Forms(obj.Name)
        For Each ctl In frm.Controls
            Debug.Print frm.Name, ctl.Name
        Next
        DoCmd.Close acForm, obj.Name, acSaveNo
    Next
    
    Set ctl = Nothing
    Set frm = Nothing
    Set obj = Nothing
    
End Sub
 
Share this answer
 
v2
Comments
oula alsheikh 14-Sep-15 3:24am    
thanks a lot you cant imagine how much happy i am
because i searched alot and all the solutions i founded needed the form to be opened in run mode
and how much difficult it will be to get controls in this way
i really admire your efforts
Gustav Brock 14-Sep-15 4:00am    
Thanks. You may mark with a five-star. Note please, that I changed acSaveYes to acSaveNo which makes more sense as no changes are done.
Have a look here: Enumerate all controls on a form[^]
 
Share this answer
 
Comments
oula alsheikh 12-Sep-15 2:42am    
thanks but this solution includes form open i mean the form must be opened at run time to get its controls
what i need and maybe is impossible is a way to get the controls with out the need to open the form at run time
Try C# code:
C#
var controlType = typeof(Control);// or UserControl
            var control= Assembly.GetExecutingAssembly()
         .GetTypes()
         .Where(t => controlType.IsAssignableFrom(t) &&
          t.Namespace == "YourNameSpace").ToList();
 
Share this answer
 
Comments
oula alsheikh 10-Sep-15 7:33am    
thanks but i want access code i mean vba
Bob Stoom 11-Sep-15 12:08pm    
It's an idea only. Try it yourself.
Maciej Los 10-Sep-15 16:03pm    
C# code in MS Access? It's impossible!
oula alsheikh 11-Sep-15 18:12pm    
that's right there is a huge difference
between c# and access

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900