[AccessD] Iterating Controls

Arthur Fuller artful at rogers.com
Sun Mar 9 13:49:00 CST 2003


I have a lot of other things on my mind today, and clearly I am now dazed
and confused, and no doubt overlooking something very obvious. Here is the
current code:

<code>

Public Sub ListDataSources()

    On Error Resume Next

 

    Dim strOutFile As String

    Dim fs As Object

    Dim a As Object

    Dim frm As Form

    Dim ctl As Control

    Dim objFrm As Object

    

    strOutFile = "c:\RecordSources.txt"

    Set fs = CreateObject("Scripting.FileSystemObject")

    Set a = fs.CreateTextFile(strOutFile, True)

    

    Application.Echo False

    

    For Each objFrm In CurrentProject.AllForms

        DoCmd.OpenForm objFrm.name, acDesign

        Set frm = Forms(objFrm.name)

        If frm.RecordSource <> "" Then

            Debug.Print objFrm.name & ": " & frm.RecordSource

            a.writeline "Form: " & objFrm.name

            a.writeline "==========================================="

            a.writeline "RecordSource:"

            a.writeline frm.RecordSource

            a.writeline

            a.writeline "Data Driven Controls"

            a.writeline "--------------------"

            

            For Each ctl In frm.Controls

                Select Case ctl.Properties("ControlType")
'.ControlType

                    Case acComboBox                             '111

                        Debug.Print ctl.name & ": Combo Box"

                        Debug.Print ctl.RowSource

                        a.writeline "Control: " & ctl.name

                        a.writeline "RowSource:"

                        a.writeline ctl.RowSource

                        

                    Case acListBox                              '110

                        Debug.Print ctl.name & ": List Box"

                        Debug.Print ctl.RowSource

                        a.writeline "Control: " & ctl.name

                        a.writeline "RowSource:"

                        a.writeline ctl.RowSource

                    Case Else

                        'do nothing

                        'Debug.Print "Ignoring " & ctl.name

                End Select

                a.writeline

            Next ctl

        End If

        Set frm = Nothing

        DoCmd.Close acForm, objFrm.name, acSaveNo

    Next

    

    a.Close

    Application.Echo True

    Set frm = Nothing

    Set fs = Nothing

    Set a = Nothing

    Set ctl = Nothing

 

 End Sub

</code>

The odd thing is that the debug window performs exactly as expected, but the
text file contains only this:

Form: Switchboard

===========================================

RecordSource:

Select * From dbo.Switchboard_Items_2002Dec02

 

Data Driven Controls

--------------------

 

I can't see why the debug.print statements dump what I want but the
a.writeline statement don't.

Arthur

-----Original Message-----
From: accessd-admin at databaseadvisors.com
[mailto:accessd-admin at databaseadvisors.com] On Behalf Of Shamil
Salakhetdinov
Sent: March 9, 2003 1:07 PM
To: accessd at databaseadvisors.com
Subject: Re: [AccessD] Iterating Controls

 

> But I'm not sure what.

Arthur,

 

You open a form but don't assign an object variable referring to this open
form instance - something like that should work:

 

dim efrm as AccessObject

dim frm as Access.Form

...

 

for each efrm in CurrentProject.AllForms

...

      DoCmd.OpenForm efrm.name, acDesign

      set frm=Forms(efrm.name)

...     

next efrm

 

HTH,

Shamil

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://databaseadvisors.com/pipermail/accessd/attachments/20030309/bf3d08e2/attachment-0001.html>


More information about the AccessD mailing list