Results 1 to 7 of 7
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Clearing check box (2000/9.0.3821 SR1)

    Our industrial learning lab uses a table (a list of courses) that has a field formatted as Yes/No. The Yes/No question is whether a given "student" has taken a particular course. We frequently have to change the answer to match a student's record. Then, when we've finished working with that student's record, we have to go back and uncheck all the courses Student A completed so we'll have a clean table to use with Student B.

    OK, I know there's a more elegant way to do all this, but here's my question: Is there a way to set up something like a "Clear All" or "Uncheck All" feature to save the time it takes to uncheck those boxes? We typically have 20 to 30 boxes to uncheck, and it's a bit tedious.

  2. #2
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Clearing check box (2000/9.0.3821 SR1)

    A couple of ways come to mind.

    Set the default value of the checkboxes to False, failing that, place the following code in the Click Event of a command button:

    <pre>Dim ctl As Control

    For Each ctl In Me.Controls
    If ctl.ControlType = acCheckBox Then
    ctl = False
    End If
    Next</pre>


    If you want to have them all checked, change ctl = false to ctl = true.

    HTH,
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Newbury, Berkshire, England
    Posts
    712
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Clearing check box (2000/9.0.3821 SR1)

    You can use an update query to do this is. In the following SQL statement, change the

  4. #4
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Newbury, Berkshire, England
    Posts
    712
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Clearing check box (2000/9.0.3821 SR1)

    BTW without the quotes!

    tablename not "tablename"

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

    Re: Clearing check box (2000/9.0.3821 SR1)

    Hi Lucas,

    I wrote the reply below on Monday, but I lost my connection to the Lounge. Bryan and Rupert have given you suggestions already that overlap mine, but I post it here anyway since there are some additional details.

    I suspect there is a design flaw here. You shouldn't have to work with a dummy table like this - you should get the state of the check boxes directly from a query that returns true/false for each course for the selected student.

    But for the current situation, there are several solutions:

    If these check boxes are the only ones on your form, you can write code that clears them all. If there are other check boxes too, you must have a way to distinguish the ones corresponding to courses, for instance by their name, or by setting the Tag property to a specific value (I used "Course" in the example). The code might look like this:

    Private Sub cmdClearCheckBoxes_Click()
    Dim ctl As Control
    For Each Ctl In Me.Controls
    If ctl.ControlType = acCheckBox Then
    If ctl.Tag = "Course" Then
    ctl.Value = False
    End If
    End If
    Next ctl
    Set ctl = Nothing
    End Sub

    You can create an update query that simply sets the Yes/No field to No for all records (leave the criteria rows in the query design window empty). You can put a button on your form that executes this query by calling DoCmd.OpenQuery "QueryName". If you want to suppress the warning "You are about to update nnn records", put
    DoCmd.SetWarnings False
    immediately before this statement, and
    DoCmd.SetWarnings True
    immediately after it. You must probably requery your form to update the status of the check boxes.

  6. #6
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Clearing check box (2000/9.0.3821 SR1)

    Bryan: Thanks for the help. In his reply to my post, Hans sniffed out the possibility of "a design flaw" in my DB. Indeed, my DB is riddled with design flaws, and this table in particular has enough flaws to fill two hours of classtime. (It's what you get when a rank amateur developer like me jumps into the deep end of the Access pool.) One such flaw is that this table--the heart of this DB--has not one, but lots of fields formatted as Yes/No. Now--months after I started this project--I can see the flaws more clearly. I want to clear out some of the clutter, but I'm treading softly so as not to turn the entire DB into a train wreck.

    I've taken the information that you, Rupert and Hans have so graciously given me and solved the problem thusly: I created an update query, then built a form with a command button that triggers the query. Bingo! My check boxes are cleared, and my colleagues are dazzled!

    Many thanks to all you guys! You're my heroes! <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

  7. #7
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Clearing check box (2000/9.0.3821 SR1)

    Hans: See my reply to Bryan and accept my thanks!

    I know you're right about the "dummy table" stuff, but this amateur developer is unsure as to how to fix the problem. I've gotten tips from you and others re: this situation in earlier posts. The fix still eludes me, but I'm taking a course in Access next month at the local community college. You've been a great help, and your response to this post has helped me solve one small problem at least! <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>

Posting Permissions

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