Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2010
    Posts
    36

    Post Unanswered: Looping through specific controls in Access form

    Hi

    I have an access form called "Home". There are a number of 20 buttons with the name of MN001 to MN020. I would like to loop through all the buttons and compare them with a list in table and when matched i would like that button to be enabled otherwise it should be disabled.
    Please any idea or help or samples.

    Thanks in advance for any one

  2. #2
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,482
    Provided Answers: 11
    for loopie = 1 to 20

    me("MN" & format(Loopie,"000")).Visible = Not me("MN" & format(Loopie,"000")).Visible

    Next
    hope this help

    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.
    DONT WORRY ABOUT THOSE WHO TALK BEHIND YOUR BACK
    THEY'RE BEHIND YOU FOR A REASON

  3. #3
    Join Date
    Dec 2010
    Posts
    36
    Thanks MYLE;

    The tip helped but when apply the following, it does not enable the button. Should i open the form in design mode?

    For Each ctl In Me.Controls
    For Loopie = 1 To 2 Step 1

    Me("MN" & Format(Loopie, "000")).Enabled = True
    'Not Me("MN" & Format(Loopie, "000")).Visible

    Next
    Next

  4. #4
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,482
    Provided Answers: 11
    bugger

    lets break it down

    you dont need the for each ctl in me.control as we know the Control Name

    so

    For Loopie = 1 To 20

    FeildName = "MN" & Format(Loopie, "000")

    Debug.print FeildName

    Does it display the FeildName in the Immediate Window and is it right

    mite have to play with the Format(Loopie, "000") until you get it right

    the "000" mean if loopie =1 then it comes "001"

    loopie =10 then it comes "010"

    Then you should be able to do this

    Me(FeildName).Enabled = True


    Next
    hope this help

    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.
    DONT WORRY ABOUT THOSE WHO TALK BEHIND YOUR BACK
    THEY'RE BEHIND YOU FOR A REASON

  5. #5
    Join Date
    Dec 2010
    Posts
    36
    Thank Myle. It helped me in figuring out what i need to accomplish.

Tags for this Thread

Posting Permissions

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