• List all objects on a form? (XP)

    Author
    Topic
    #420546

    I really hope grovel there is an easy add-in or something that will do this….is there an easy way to get a list of all objects on a form?

    Viewing 0 reply threads
    Author
    Replies
    • #952583

      Depends on where you want the list to end up. You can do something like this:

      Sub ListControls()
      Dim frm As Form
      Dim ctl As Control
      DoCmd.OpenForm “frmMyForm”, acDesign
      Set frm = Forms!frmMyForm
      For Each ctl In frm.Controls
      Debug.Print ctl.Name
      Next ctl
      DoCmd.Close acForm, “frmMyForm”
      Set ctl = Nothing
      Set frm = Nothing
      End Sub

      This will list all controls in the Immediate window.

      • #952587

        (Edited by HansV to make URL clickable – see Help 19)

        Am I off base here on this one, looking at this explanation, am not sure it is going to list your form objects one by one…or all objects by name in your database…
        http://support.microsoft.com/?kbid=210347%5B/url%5D

      • #952591

        Instead of debug.print, what would I use to export the list to, say, a notepad file (for faster coding)?
        grin cool

        • #952603

          Try this:

          Sub ListControls()
          Dim frm As Form
          Dim ctl As Control
          Dim strForm As String
          Dim f As Integer
          strForm = InputBox(“Enter name of form”)
          If strForm = “” Then Exit Sub
          f = FreeFile
          Open “C:List.txt” For Output As #f
          DoCmd.OpenForm strForm, acDesign
          Set frm = Forms(strForm)
          For Each ctl In frm.Controls
          Print #f, ctl.Name
          Next ctl
          DoCmd.Close acForm, strForm
          Close #f
          Set ctl = Nothing
          Set frm = Nothing
          End Sub

          Replace C:List.txt with the path and name you prefer.

          • #952604

            Francois, Hans,
            Thank you for your solutions, both work exactly how I need them to. I changed the code a little bit, created a new table, and after For Each, I just used rst.AddNew, creating a list and it got the job done. Thanks.

        • #952602

          Modify Hans’ code to :

          Sub ListControls()
          Dim frm As Form
          Dim ctl As Control
          DoCmd.OpenForm “frmMyForm”, acDesign
          Set frm = Forms!frmMyForm
          Open “c:testfile.txt” For Output As 1
          For Each ctl In frm.Controls
          Write #1, ctl.Name
          Next ctl
          Close #1
          DoCmd.Close acForm, “frmMyForm”
          Set ctl = Nothing
          Set frm = Nothing
          End Sub

          This will create a file named testfile in the root directory of your c drive. You can open it with Notepad

    Viewing 0 reply threads
    Reply To: List all objects on a form? (XP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: