Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2004
    Posts
    31

    Unanswered: Tips on improving my code?

    From the code below:
    Giros.Controls(Giro1).Visible = False
    Giros.Controls("giro2").Visible = False
    Giros.Controls("giro3").Visible = False
    Giros.Controls("giro4").Visible = False
    Giros.Controls("giro5").Visible = False
    Giros.Controls("giro6").Visible = False
    Giros.Controls("giro7").Visible = False
    Giros.Controls("giro8").Visible = False
    Giros.Controls("giro9").Visible = False
    Giros.Controls("giro10").Visible = False
    Giros.Controls("giro11").Visible = False
    Giros.Controls("giro12").Visible = False
    is there any way that I can do a loop that would go from 1-12 in the parenthesis and do it all in a more "clean" fashion?

  2. #2
    Join Date
    Apr 2004
    Posts
    173

    code problem

    ususally if i'm going to do something similar on a form i cheat and use the tag property. i set it to -1 and then loop through all the controls on the form for those that have their tags set to -1 and hide them or show them based on a boolean i pass in.

    public sub hide(state as boolean)
    dim ctrl as control
    for each ctrl in me.controls
    if ctrl.tag = -1 then ctrl.visible = state
    next ctrl
    end sub

    i don't know if this helps sorry if it doesn't

  3. #3
    Join Date
    Jun 2004
    Posts
    31
    Thank you I will try it out and see what happens

  4. #4
    Join Date
    Apr 2003
    Location
    Alabama, USA
    Posts
    154
    Quote Originally Posted by peto813
    is there any way that I can do a loop that would go from 1-12 in the parenthesis and do it all in a more "clean" fashion?
    Code:
    For i = 1 to 12
    Giros.Controls("giro" & i).Visible = False
    Next i
    This will set the .Visible property to false for all controls in Giros(?) that are named giro1, giro2, ... , giro12.

    Hope this helps!
    Last edited by Cosmos75; 06-29-04 at 22:06. Reason: Added formatting to code.
    http://AccessDB.Info

    You live and learn. At any rate, you live. - Douglas Adams

Posting Permissions

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