Results 1 to 9 of 9
  1. #1
    5 Star Lounger
    Join Date
    Nov 2004
    Location
    Wilmington, North Carolina, USA
    Posts
    1,196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    List all objects on a form? (XP)

    I really hope <img src=/S/grovel.gif border=0 alt=grovel width=31 height=23> 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?
    ____________________________
    Jeremy
    "If you spend more on coffee than on IT security, then you will be hacked. What&#39;s more, you deserve to be hacked." -Richard Clarke

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: List all objects on a form? (XP)

    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.

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Jacksonville,NC, USA
    Posts
    705
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List all objects on a form? (XP)

    (Edited by HansV to make URL clickable - see <!help=19>Help 19<!/help>)

    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
    NMP <img src=/S/cool.gif border=0 alt=cool width=15 height=15>

    If you can't convince them, confuse them. - Harry Truman <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: List all objects on a form? (XP)

    The code from the MSKB article will list all forms, or all reports, etc., not all objects (controls) on an individual form.

  5. #5
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Jacksonville,NC, USA
    Posts
    705
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List all objects on a form? (XP)

    Many thank yous...was being a bit lazy wasn't I?

    http:// wopr.com
    NMP <img src=/S/cool.gif border=0 alt=cool width=15 height=15>

    If you can't convince them, confuse them. - Harry Truman <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>

  6. #6
    5 Star Lounger
    Join Date
    Nov 2004
    Location
    Wilmington, North Carolina, USA
    Posts
    1,196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List all objects on a form? (XP)

    Instead of debug.print, what would I use to export the list to, say, a notepad file (for faster coding)?
    <img src=/S/grin.gif border=0 alt=grin width=15 height=15> <img src=/S/cool.gif border=0 alt=cool width=15 height=15>
    ____________________________
    Jeremy
    "If you spend more on coffee than on IT security, then you will be hacked. What&#39;s more, you deserve to be hacked." -Richard Clarke

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: List all objects on a form? (XP)

    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.

  8. #8
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List all objects on a form? (XP)

    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
    Francois

  9. #9
    5 Star Lounger
    Join Date
    Nov 2004
    Location
    Wilmington, North Carolina, USA
    Posts
    1,196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List all objects on a form? (XP)

    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.
    ____________________________
    Jeremy
    "If you spend more on coffee than on IT security, then you will be hacked. What&#39;s more, you deserve to be hacked." -Richard Clarke

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •