[AccessD] Get all controls on all forms

A.D.TEJPAL adtp at airtelbroadband.in
Tue Jul 31 07:29:29 CDT 2007


Sander,

    Sample subroutine P_ListAllControlsAllForms(), as given below, will populate table named T_AllControls with the names of all forms in the db as well as all controls thereon, along with particulars of ControlType. If any form happens to be blank (no controls), its name will appear against field FormName, leaving the ControlName & ControlType fields blank.

    Before using this procedure, please make sure that table T_AllControls is available, with fields named FormName (text type), ControlName (text type) and ControlType (number type).

    Note: 
        This procedure should preferably be run directly from VBA window. If you wish to run it from a test form, the code should be modified suitably so as to prevent opening of that test form. This is because, each form in AllForms collection gets opened turn by turn, in design view. If test form also gets opened in design view, further execution of code will get interrupted.

Best wishes,
A.D.Tejpal
---------------

Sample Subroutine
(For listing all forms & their controls)
====================================
Sub P_ListAllControlsAllForms()
    Dim obj As AccessObject, ct As Control
    Dim rst As DAO.Recordset
    Dim FormName As String
    
    ' Clear existing contents of table T_AllControls
    CurrentDb.Execute "DELETE FROM " & _
                            "T_AllControls;", dbFailOnError
    
    Set rst = CurrentDb.OpenRecordset("T_AllControls")
    
    For Each obj In CurrentProject.AllForms
        FormName = obj.Name
        DoCmd.OpenForm FormName, acDesign
        
        If Forms(FormName).Controls.Count > 0 Then
            For Each ct In Forms(FormName).Controls
                rst.AddNew
                With rst.Fields
                    !FormName = FormName
                    !ControlName = ct.Name
                    !ControlType = ct.ControlType
                End With
                rst.Update
            Next
        Else
            rst.AddNew
            rst.Fields("FormName") = FormName
            rst.Update
        End If
        
        DoCmd.Close acForm, FormName, acSaveNo
    Next
    
    rst.Close
    Set rst = Nothing
    Set ct = Nothing
    Set obj = Nothing
End Sub
====================================

  ----- Original Message ----- 
  From: Sad Der 
  To: Acces User Group 
  Sent: Monday, July 30, 2007 19:25
  Subject: [AccessD] Get all controls on all forms


  Hi group,

  Does anybody have piece of code that retrieves all
  controles on all forms in a database?
  I need to store these in a database.

  Thnx!

  Regards,

  Sander


More information about the AccessD mailing list