Results 1 to 4 of 4
  1. #1
    JennyL is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2017
    Posts
    51

    Option Group Hide buttons VBA codes

    Hi all,

    I have a form with an option group frame. When a user click on the radio button of the option group, i want the command button to display or hide. I have 9 buttons or could be more in the future, is there any shorter code that i can write besides repeating the following If / ElseIf statement 9 or more times for each option radio button?

    Private Sub ArchiveFrame_Click()
    If Me.ArchiveFrame = 1 Then
    Me.CmdArchiveCustomer.Visible = True
    Me.CmdArchiveCAD.Visible = False
    Me.CmdArchiveCC.Visible = False
    Me.CmdArchiveCO.Visible = False
    Me.CmdArchivePay.Visible = False
    Me.CmdArchiveRRC.Visible = False
    Me.CmdArchiveRRD.Visible = False
    Me.CmdArchiveUSLB.Visible = False

    ElseIf Me.ArchiveFrame = 2 Then
    Me.CmdArchiveCustomer.Visible = False
    Me.CmdArchiveCAD.Visible = True
    Me.CmdArchiveCC.Visible = False
    Me.CmdArchiveCO.Visible = False
    Me.CmdArchivePay.Visible = False
    Me.CmdArchiveRRC.Visible = False
    Me.CmdArchiveRRD.Visible = False
    Me.CmdArchiveUSLB.Visible = False


    End If
    End Sub





    I know the above code will work, but is there a better way to do this if statement?

    Thanks,

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    One way:

    Me.CmdArchiveCustomer.Visible = (Me.ArchiveFrame = 1)
    Me.CmdArchiveCAD.Visible = (Me.ArchiveFrame = 2)
    Me.CmdArchiveCC.Visible = (Me.ArchiveFrame = 3)
    Me.CmdArchiveCO.Visible = (Me.ArchiveFrame = 4)
    Me.CmdArchivePay.Visible = (Me.ArchiveFrame = 5)
    Me.CmdArchiveRRC.Visible = (Me.ArchiveFrame = 6)
    Me.CmdArchiveRRD.Visible = (Me.ArchiveFrame = 7)
    Me.CmdArchiveUSLB.Visible = (Me.ArchiveFrame = 8)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    JennyL is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2017
    Posts
    51
    Quote Originally Posted by JennyL View Post
    Hi all,

    I have a form with an option group frame. When a user click on the radio button of the option group, i want the command button to display or hide. I have 9 buttons or could be more in the future, is there any shorter code that i can write besides repeating the following If / ElseIf statement 9 or more times for each option radio button?

    Private Sub ArchiveFrame_Click()
    If Me.ArchiveFrame = 1 Then
    Me.CmdArchiveCustomer.Visible = True
    Me.CmdArchiveCAD.Visible = False
    Me.CmdArchiveCC.Visible = False
    Me.CmdArchiveCO.Visible = False
    Me.CmdArchivePay.Visible = False
    Me.CmdArchiveRRC.Visible = False
    Me.CmdArchiveRRD.Visible = False
    Me.CmdArchiveUSLB.Visible = False

    ElseIf Me.ArchiveFrame = 2 Then
    Me.CmdArchiveCustomer.Visible = False
    Me.CmdArchiveCAD.Visible = True
    Me.CmdArchiveCC.Visible = False
    Me.CmdArchiveCO.Visible = False
    Me.CmdArchivePay.Visible = False
    Me.CmdArchiveRRC.Visible = False
    Me.CmdArchiveRRD.Visible = False
    Me.CmdArchiveUSLB.Visible = False


    End If
    End Sub



    I know the above code will work, but is there a better way to do this if statement?

    Thanks,

    It worked! Thank you so much!!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. How to hide the frame of a option group
    By Bradex in forum Forms
    Replies: 2
    Last Post: 04-29-2016, 06:55 AM
  2. Option group radio buttons
    By sharonir22 in forum Forms
    Replies: 3
    Last Post: 07-04-2015, 11:11 PM
  3. Radio buttons within Option Group not working
    By losingmymind in forum Programming
    Replies: 7
    Last Post: 01-09-2013, 03:09 PM
  4. Use of option group buttons
    By sireesha in forum Forms
    Replies: 1
    Last Post: 10-25-2012, 01:20 PM
  5. option group radio buttons
    By ManC in forum Forms
    Replies: 9
    Last Post: 03-08-2010, 03:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums