Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10

    Unanswered: for Each Control In Me.Controls

    Code:
        For Each Control In Me.Controls
    'do something
        Next Control
    How can I return the name of every control on my form?
    I'm using the above loop to go through the controls and something as simple as displaying each controls name in the loop would solve my problem...
    MsgBox Control.Name or something?!

    Any suggestions? Cheers
    George
    Home | Blog

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Code:
      Dim ctl                As Control
      For Each ctl In Me.Controls
        Debug.Print ctl.Name
      Next ctl
    Paul

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Just a quick reply to say thanks to Paul.
    This works great!

    I guess the extension to the problem is:

    Can I return the control type? Example, I want to loop through all textboxes, and textboxes only!
    George
    Home | Blog

  4. #4
    Join Date
    Jan 2007
    Location
    California, USA
    Posts
    520
    Look up Controls in Access help. It will show you the list of control types and it even has the sample code to show the control type in a loop like Paul showed you.

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Ach, I did that earlier and read through a hell of a lot of wrong answers

    I will look into it again tomorrow - Cheers Vic
    George
    Home | Blog

  6. #6
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Here's a hint from one of my templates:

    Code:
        Select Case ctl.ControlType
          Case acTextBox, acComboBox, acListBox, acOptionGroup, acCheckBox
    Paul

  7. #7
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I searched "controltype" on access help to no avail yesterday - still doesnt appear today...
    So instead I just wrote controltype, placed my cursor in it and hit f1, bingo.
    Silly access.

    Clever Vic & Paul
    George
    Home | Blog

  8. #8
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Dim ctl As Control
    For Each ctl In Me.Controls
    If TypeOf ctl Is TextBox Then
    Debug.Print ctl.Name
    End If
    Next ctl
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  9. #9
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Oooh, that's a clever way of doing it too!
    George
    Home | Blog

Posting Permissions

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