+ Reply to Thread
Results 1 to 4 of 4

Check box making a command button work

  1. #1
    Registered User
    Join Date
    11-06-2005
    Posts
    13

    Check box making a command button work

    Hello

    I have a check box on a sheet from the forms toolbar
    I would like to make a command button work only when the check box is ticked

    Thank you

  2. #2
    JakeyC
    Guest

    Re: Check box making a command button work

    Insert the following at the beginning of your CommandButton1_click
    code:

    If CheckBox1.Value = True Then
    Exit Sub
    End If

    This way, the sub will end before anything gets done.


  3. #3
    JakeyC
    Guest

    Re: Check box making a command button work

    Apologies - my code will run when the box is UNchecked! Change 'True'
    to 'False' as needed...


  4. #4
    Dave Peterson
    Guest

    Re: Check box making a command button work

    I used a button from the forms toolbar--is that what you meant?

    You could either add some code to the button's code:

    Option Explicit
    Sub btnClick()

    If ActiveSheet.CheckBoxes("Check box 1").Value = xlOff Then
    MsgBox "nope, not today!"
    Exit Sub
    End If

    'your real code here

    MsgBox "it's working"

    End Sub

    Or you could disable the button (or hide it) when the checkbox changes:

    Option Explicit
    Sub CBXClick()
    ActiveSheet.Buttons("button 1").Enabled _
    = CBool(ActiveSheet.CheckBoxes("Check box 1").Value = xlOn)
    'or hide it???
    ActiveSheet.Buttons("button 1").Visible _
    = CBool(ActiveSheet.CheckBoxes("Check box 1").Value = xlOn)
    End Sub

    If you really meant a commandbutton from the control toolbox toolbar, something
    like:

    Sub CBXClick()
    ActiveSheet.CommandButton1.Enabled _
    = CBool(ActiveSheet.CheckBoxes("Check box 1").Value = xlOn)
    'or to hide it
    ActiveSheet.CommandButton1.Visible _
    = CBool(ActiveSheet.CheckBoxes("Check box 1").Value = xlOn)
    End Sub

    But the same kind of check inside the commandbutton's code would work ok (like
    in btnclick procedure).


    Rmagic wrote:
    >
    > Hello
    >
    > I have a check box on a sheet from the forms toolbar
    > I would like to make a command button work only when the check box is
    > ticked
    >
    > Thank you
    >
    > --
    > Rmagic
    > ------------------------------------------------------------------------
    > Rmagic's Profile: http://www.excelforum.com/member.php...o&userid=28595
    > View this thread: http://www.excelforum.com/showthread...hreadid=484465


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1