[AccessD] Iterating Controls

Shamil Salakhetdinov shamil at smsconsulting.spb.ru
Sun Mar 9 12:08:08 CST 2003


> 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
  ----- Original Message ----- 
  From: Arthur Fuller 
  To: accessd at databaseadvisors.com 
  Sent: Sunday, March 09, 2003 6:48 PM
  Subject: RE: [AccessD] Iterating Controls


  Swing and a miss! I thought you had a home run there but no. Here's the whole sub, and all it prints is the names of the forms. Here's the entire sub:

  <code>

  Public Sub ListRowSources()

      On Error Resume Next

      Dim frm As Object, db As CurrentProject, ctl As Control

      Dim strOutFile As String

      strOutFile = "RowSources.txt"        '"c:\testfile.txt"

      Set db = CurrentProject

      Dim fs As Object, a As Object

      Set fs = CreateObject("Scripting.FileSystemObject")

      Set a = fs.CreateTextFile(strOutFile, True)



      Set db = CurrentProject



      Application.Echo False

      

      Debug.Print "Analyzing Row Sources"



      'Walk through forms

      For Each frm In db.AllForms

          DoCmd.OpenForm frm.name, acDesign

          a.writeline "Form: " & frm.name

          'Walk through controls

          For Each ctl In frm.Controls

              With ctl

                  Debug.Print ctl.Properties("Name")

                  Select Case .ControlType

                      Case acComboBox

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

                          Debug.Print ctl.RowSource

                          a.writeline "Control: " & ctl.name

                          a.writeline "RowSource"

                          a.writeline ctl.RowSource

                          

                      Case acListBox

                    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

                  End Select

              End With

          Next ctl

          DoCmd.Close acForm, frm.name

      Next frm



      Application.Echo True

      

      Set frm = Nothing

      Set db = Nothing

      Set fs = Nothing

      Set a = Nothing



   End Sub

  </code?



  All it does is print the form names. Not a single mention of any control on any form. Clearly it's more wrong than On Error. But I'm not sure what.

  Arthur



  -----Original Message-----
  From: accessd-admin at databaseadvisors.com [mailto:accessd-admin at databaseadvisors.com] On Behalf Of Michael R Mattys
  Sent: March 9, 2003 10:26 AM
  To: accessd at databaseadvisors.com
  Subject: Re: [AccessD] Iterating Controls



  Hi Arthur,



  You're looking too far to see it up close :)

  On Error Resume Next



  Mike Mattys



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


More information about the AccessD mailing list