[AccessD] Iterating Controls: Solved

Arthur Fuller artful at rogers.com
Mon Mar 10 15:14:00 CST 2003


For those interested, here's a sub that walks the forms and grabs the
data-driven record sources and within each form, the data-driven row sources
for combo boxes and list boxes. Watch for wrap.
<code>
'-------------------------------------------------------------------------
' Procedure : ListDataSources
' DateTime  : 10/03/2003
' Author    : Arthur Fuller
' Purpose   : List the data sources for all forms and data-driven controls
'-------------------------------------------------------------------------
Public Sub ListDataSources()
    Dim strOutFile As String
    Dim fs As Object
    Dim a As Object
    Dim frm As Form
    Dim ctl As Control
    Dim objFrm As Object
    Dim i As Integer
    
    strOutFile = "c:\RyersonDataSources.txt"
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.CreateTextFile(strOutFile, True)
    
    Application.Echo False
    
    For Each objFrm In CurrentProject.AllForms
        i = 0
        DoCmd.OpenForm objFrm.name, acDesign
        Set frm = Forms(objFrm.name)
        a.WriteLine
"========================================================================="
        a.WriteLine "Form: " & objFrm.name
        a.WriteLine
"========================================================================="
Debug.Print objFrm.name & ": " & frm.RecordSource
        
        If frm.RecordSource <> "" Then
            a.WriteLine "RecordSource:"
            a.WriteLine frm.RecordSource
            a.WriteLine
        Else
            a.WriteLine "Unbound form"
        End If
    
        For Each ctl In frm.Controls
            Select Case ctl.Properties("ControlType")       '.ControlType
                Case acComboBox
                    If ctl.Properties("RowSourceType") =
"Table/View/StoredProc" Then
                        i = 1
                    End If
                        
                Case acListBox                              '110
                    If ctl.Properties("RowSourceType") =
"Table/View/StoredProc" Then
                        i = 1
                    End If
                
                Case Else
                    'do nothing
                    'Debug.Print "Ignoring " & ctl.name
            End Select
        Next ctl
        
        If i > 0 Then
            a.WriteLine "Data Driven Controls"
            a.WriteLine "--------------------"
        End If
        
        For Each ctl In frm.Controls
            Select Case ctl.Properties("ControlType")       '.ControlType
                Case acComboBox                             '111
                    If ctl.Properties("RowSourceType") =
"Table/View/StoredProc" Then
                        Debug.Print ctl.name & ": Combo Box"
                        Debug.Print ctl.RowSource
                        a.WriteLine "Control: " & ctl.name
                        a.WriteLine "RowSource:"
                        a.WriteLine ctl.RowSource
                        a.WriteLine
                    End If
                        
                Case acListBox                              '110
                    If ctl.Properties("RowSourceType") =
"Table/View/StoredProc" Then
                        Debug.Print ctl.name & ": List Box"
                        Debug.Print ctl.RowSource
                        a.WriteLine "Control: " & ctl.name
                        a.WriteLine "RowSource:"
                        a.WriteLine ctl.RowSource
                        a.WriteLine
                    End If
                
                Case Else
                    'do nothing
                    'Debug.Print "Ignoring " & ctl.name
            End Select
        Next ctl
        
        Set frm = Nothing
        DoCmd.Close acForm, objFrm.name, acSaveNo
        a.WriteLine
    Next objFrm
    
    a.Close
    Application.Echo True
    Set frm = Nothing
    Set fs = Nothing
    Set a = Nothing
    Set ctl = Nothing
    Set objFrm = Nothing

 End Sub
</code>





More information about the AccessD mailing list