Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    Lounger
    Join Date
    Jul 2003
    Location
    Notre Dame, Indiana, USA
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Multiple Checkboxes- click one to select all (Access 2002)

    <img src=/S/brickwall.gif border=0 alt=brickwall width=25 height=15> I have a form on which I have several checkboxes that may or may not apply to the data I am entering. Most of the time all of the checkboxes need to be checked. I want to create a "checks all" check box that, when checked, will select all of the checkboxes.

    I know that this sort of thing can be done, because I use a proprietary database for ad order entry that has many such lists where you can check one or more items, or you can simply "check all" with one click.

    Any help or direction is greatly appreciated. <img src=/S/dizzy.gif border=0 alt=dizzy width=15 height=15>

  2. #2
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Multiple Checkboxes- click one to select all (Access 2002)

    In the OnClick Event of your checkbox try Me!MyControlName = True

    You can either list each control name or set up a loop.

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

    Re: Multiple Checkboxes- click one to select all (Access 2002)

    If your check boxes have arbitrary names, you'll have to list them (unless they are the only check boxes on the form, but that is a dangerous assumption, you might need other check boxes later):

    Private Sub chkCheckAll_Click
    If chkCheckAll = True Then
    chkFirst = True
    chkSecond = True
    ...
    chkLast = True
    End If
    End Sub

    If you have named your check boxes (for example) chkCheck1 to chkCheck8, you can use

    Private Sub chkCheckAll_Click
    Dim i As Long
    If chkCheckAll = True Then
    For i = 1 To 8
    Me.Controls("chkCheck" & i) = True
    Next i
    End If
    End Sub

  4. #4
    Lounger
    Join Date
    Jul 2003
    Location
    Notre Dame, Indiana, USA
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Multiple Checkboxes- click one to select all (Access 2002)

    This seems to work, as far as getting the yes/no selection into the underlying table, but it doesn't cause a "check mark" to appear in the check box. Do you know of a way to do this as well?

    Thanks for your help. I no longer feel like <img src=/S/brickwall.gif border=0 alt=brickwall width=25 height=15>

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

    Re: Multiple Checkboxes- click one to select all (Access 2002)

    If you use the names of the check box controls in the code, they should be checked automatically, and if the controls are bound to fields, the underlying data should be updated too.

  6. #6
    Lounger
    Join Date
    Jul 2003
    Location
    Notre Dame, Indiana, USA
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Multiple Checkboxes- click one to select all (Access 2002)

    Hans:
    I have never written code before. Could you give me a sample? My checkbox names are 'ck1', 'ck2', 'ck3', 'ck4' and 'ck5'. They are bound to fields named 'matcklist', 'slvcklist', 'graphcklist', 'matdeadline' and 'spcdeadline', respectively.

    Again, any help you can offer is greatly appreciated. I am not exactly a newbie, but sometimes I think I know just enough to think I know what I'm doing, but not enough to breeze through a task.

    srs

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

    Re: Multiple Checkboxes- click one to select all (Access 2002)

    OK, so you have a form bound to a table; it contains (among others), 5 check boxes named ck1 to ck5, bound to fields in the table. These fields are of type Yes/No.

    You have a sixth check box on the form that is not bound to any field in the table (its Control Source property is empty). Let's say you named it ckAll.
    <UL><LI>With the form open in design view, select ckAll by clicking on it.
    <LI>Activate the Events tab of the Properties window.
    <LI>Click in the box labeled On Click.
    <LI>Select Event Procedure from the dropdown list of the On Click event.
    <LI>Next, click the builder button (the three dots ... to the right).
    <LI>You will be taken to the Visual Basic Editor. You will see the code module belonging to your form, with the first and last line of the event procedure already created for you, and the blinking insertion cursor in the empty line between them:

    Private Sub ckAll_Click()

    End Sub

    (if you used a different name than ckAll, you will see that followed by _Click)
    <LI>Enter the following code between the Sub ... and End Sub lines. I like to indent code by using the Tab key, but that's a matter of taste/convention. Lines starting with an apostroph ' are comments, they are meant to explain bits of code but they are not part of the code.

    ' Declare a variable
    Dim i As Long
    ' Test if user ticked the ckAll check box
    If ckAll = True Then
    ' Loop through the five check boxes
    For i = 1 To 5
    ' Tick the i-th check box by setting its value to True
    Me.Controls("ck" & i) = True
    Next i
    End If

    <LI>Switch back to Access (using the Windows task bar or Alt+Tab)
    <LI>Close the form and save changes.
    <LI>Open the form in form view to test it. If you tick ckAll, all check boxes ck1 through ck5 should become checked too. This will be saved in the corresponding fields in the table when you move to another record or close the form.[/list]There are some bells and whistles you could add, but first try to get this working correctly.

  8. #8
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Multiple Checkboxes- click one to select all (Access 2002)

    does he need to refresh the form at the end of the code ?

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

    Re: Multiple Checkboxes- click one to select all (Access 2002)

    In my test form, that wasn't necessary.

  10. #10
    Lounger
    Join Date
    Jul 2003
    Location
    Notre Dame, Indiana, USA
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Multiple Checkboxes- click one to select all (Access 2002)

    Hans:

    I've been out of the office for several days, and only just tried the code writing exercise you gave me. Unfortunately, I get an error 438: 'object doesn't support this property or method'. When I click debug , it highlights "Me.controls ("ck" & i) = True". Any ideas on what I'm doing incorrectly?
    srs
    PS- I'm not a 'he'

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

    Re: Multiple Checkboxes- click one to select all (Access 2002)

    Let's see if we can find out what's going on. If you're in the Visual Basic Editor, what is the caption (title) of the window that contains the code you entered (among which the line on which the error occurs)?

    PS: the assumption about your gender was not mine <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  12. #12
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Multiple Checkboxes- click one to select all (Access 2002)

    sorry about the gender assumption

  13. #13
    Lounger
    Join Date
    Jul 2003
    Location
    Notre Dame, Indiana, USA
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Multiple Checkboxes- click one to select all (Access 2002)

    It's ok. I just thought it was funny, and wanted to set the record straight. If we were speaking in the abstract, 'he' would be just fine with me! <img src=/S/blackteeth.gif border=0 alt=blackteeth width=20 height=20>
    Any more ideas?
    srs

  14. #14
    2 Star Lounger
    Join Date
    Apr 2003
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Multiple Checkboxes- click one to select all (Access 2002)

    Okay, I'm having the same question as the initial poster -- I would like to click one check box and have all of the check boxes select. However, I am in a slightly different situation than the original poster -- I just have one checkbox in the "detail" section of my form and depending on how many records are returned in the query, the number of check boxes is going to vary, so I'm not sure if a simple loop will work in that case. I tried doing the:

    Private Sub ckCheckAll_Click()
    If ckCheckAll = True Then
    ckChecked = True
    End If
    End Sub

    But it only checks the first checkbox. Can this be done?

    Thanks,
    Kindra

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

    Re: Multiple Checkboxes- click one to select all (Access 2002)

    Is this a continuous form?

Page 1 of 2 12 LastLast

Posting Permissions

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