Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Command Buttons Hide (A2000)

    Good Morning,

    I have several Command Buttons on a form, none of which are in any type of group (option group). On Open of the form I only want 1 of those buttons visible. Now I know the code for making a control visible or not, what I would like to do is, rather than name each of the command buttons (to make each cmdbutton NOT Visible, making the code rather lengthy and unessary, if I knew the correct code), except for the 1, in code something like a FOR EACH.

    I hope I was clear and someone can point me in the right direction.

    i.e. cmd1, cmd2 cmd3 on frm1. OnOpen, I want Only cmd1 visible, the rest NOT visible.

    Thanks in advance.
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

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

    Re: Command Buttons Hide (A2000)

    You can set the Visible property to No in design view. That way you don't need code. If you prefer code, you can use the Controls collection of the form. One possibility:

    ' Hide ALL command buttons
    Dim ctl As Control
    For Each ctl In Me.Controls
    If ctl.ControlType = acCommandButton Then
    ctl.Visible = False
    End If
    Next ctl
    Set ctl = Nothing
    ' Then unhide a specific one
    Me.cmd1.Visible = True

    Another possibility, if they are really named cmd1, cmd2, cmd3 etc:

    Dim i As Integer
    For i = 2 To 37 ' substitute correct number
    Me.Controls("cmd" & i).Visible = False
    Next i

  3. #3
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Command Buttons Hide (A2000)

    Thank you Hans! Works like a charm....I used option 1. Option 2 would have only worked if in fact the command buttons were the names I stated in my post. However, I only used those names as a reference.

    Thanks.
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

Posting Permissions

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