Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Check Box (2000)

    I am trying to use a label as a checkbox and replace the check with an X. I am using the following code behind the worksheet the label is on:

    Public blnCheck As Boolean

    Private Sub lblCheck_Click()
    Call swapCheck
    End Sub

    Private Sub lblClick_Click()
    Call swapCheck
    End Sub

    Private Sub swapCheck()
    blnCheck = Not blnCheck
    lblCheck.Caption = IIf(blnCheck, "X", "")
    End Sub

    This code is not working. The properties for the label are: Borderstyle:1, name: Chk1, Caption: "X".
    Thanks for your help.

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

    Re: Check Box (2000)

    If the name of the label is Chk1, you should use that name instead of lblCheck or lblClick in your code:

    Private Sub Chk1_Click()
    SwapCheck
    End Sub

    Private Sub SwapCheck()
    blnCheck = Not blnCheck
    Chk1.Caption = IIf(blnCheck, "X", "")
    End Sub

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check Box (2000)

    That worked for the one check box. I tried to copy it down but I lose the ability to click on it. Would I have to write code for each label box or is there other code I could use so that I can copy the label box down in a column?

  4. #4
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Check Box (2000)

    You would have to have a variable for each and code for each.

    Why not just use a checkbox object? You can place one in a cell and copy the cell down

    Another option is to use the cell itself to contain the "X" and use the dbl-click event to change the contents. Add something like this to the worksheet object in code (not a regular module). Then when you dbl-click a cell in col A (change as appropriate) it will add an "X" if empty or clear the contents if not empty.

    Steve

    <pre>Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Excel.Range, Cancel As Boolean)
    If Not Intersect(Target, Range("A:A")) Is Nothing Then
    If IsEmpty(Target.Cells(1, 1).Value) Then
    Target.Cells(1, 1).Value = "X"
    Else
    Target.Cells(1, 1).ClearContents
    End If
    Cancel = True
    End If
    End Sub</pre>


    You could also use the selection change event, but that will be triggered whether from a click or just movement.

    Steve

  5. #5
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Check Box (2000)

    Another way to do it is to create the object and assign them all to the same macro. The macro will determine the object calling the code and changes the text of that object.

    Steve

    <pre>Sub CheckObject()
    Dim shp As Shape
    Set shp = ActiveSheet.Shapes(Application.Caller)
    If shp.TextFrame.Characters.Text = "" Then
    shp.TextFrame.Characters.Text = "X"
    Else
    shp.TextFrame.Characters.Text = ""
    End If
    End Sub</pre>


Posting Permissions

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