Results 1 to 7 of 7
  1. #1
    Lounger
    Join Date
    May 2002
    Location
    Wytheville,VA, Virginia, USA
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Checkbox 'group' (A97 SR2)

    I have a form with 5 check boxes (as an example). We'll call them chk1 through chk5. I want Chk1 to default to True for each new record. Not a problem, I can set that in the default value, but it is not really important as this box is for display only. The fun part comes when I get to the other 4 boxes. Chk1 is basically used as a "no errors" selection. Chk2 - 5 are possible error types. Any combination of 2-5 can be used for each record. Is there an easy way to toggle these boxes without coding every box? For example, couldn't I just write a code that says
    "If any of 2-5 =true, 1 = false. If 1 = true, 2-5=false"

    I'm asking because I have 5 of these groups on the form to code and while it wouldn't be hard to do, i would rather not spend the time coding each individual box. As it stands now, I can safely rename all the boxes to accomidate code requirements.

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Checkbox 'group' (A97 SR2)

    As I understand it, chk1 does not allow data entry, rather it only shows the status of the other boxes, correct? Then set it's control source to this:
    = Not (chk2 + chk3 + chk4 + chk5)
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Checkbox 'group' (A97 SR2)

    <pre>Private Sub ToggleChkBox(chk As CheckBox)
    Dim ctl As Control

    If chk.Name = "chk1" and chk = True Then
    For each ctl In Me.Controls
    If ctl.ControlType = acCheckbox And ctl.Name <> "Chk1" Then
    ctl.Value = False
    End If
    Next ctl
    Else
    If chk = True Then
    Me.Chk1 = False
    End If
    End If
    End Sub</pre>


    Put that in the form module and call it from each checkbox's AfterUpdate event like this:

    <pre>ToggleChkBox Screen.ActiveControl</pre>

    Charlotte

  4. #4
    Lounger
    Join Date
    May 2002
    Location
    Wytheville,VA, Virginia, USA
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Checkbox 'group' (A97 SR2)

    Thanks for the ideas. Charlotte's example gives me exactly what I want for 1 group of checkboxes. I need to be able to check chk1 and have it clear the others. Also, as soon as one of the others is checked, chk1 is cleared. However, is it possible to set up arrays on the same form so that I can put "clones" of chk1 on the same form? What I am looking for is something like:
    ...
    For each ctl in MyArray
    if control name <> name of first checkbox in Myarray then
    ctl.value=False
    ...

    I could even set MyArray=1 to 5, MyArray2 = 6 to 10, etc. (Just a thought)

    This way, I could use (essentially) the same code for boxes 1-5, 6-10, 11-15, etc with boxes 1-5 working exactly as Charlotte's example with chk1 being the "all clear" box, chk6 would be the "all clear" for 7-10, and so on. I have looked at the help files on arrays, but I just don't get how to set up an array of objects like checkboxes. Am I spitting in the wind, here?

    Of course, if there's a better way to do it, I'm open to that, too. Just seems to me like an array type activity would get the job done. Any other suggestions are definitely welcome.

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Checkbox 'group' (A97 SR2)

    There are no control arrays in Access, but you can build an array of control *names* and use that. I've attached a sample database that demonstrates.
    Attached Files Attached Files
    Charlotte

  6. #6
    Lounger
    Join Date
    May 2002
    Location
    Wytheville,VA, Virginia, USA
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Checkbox 'group' (A97 SR2)

    WOW! That is EXACTLY what I need. Thanks!
    P.S.
    Teach me Obi-Wan. I have much to learn of the VB force.

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Checkbox 'group' (A97 SR2)

    <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15> Well, in that case, Luke, you could also use a couple of Collections of Checkbox objects and refer to the controls directly as members of the collection instead of using an array of checkbox names. One of these days when I have time, I'll play with that and add it to a much classier demo database.
    Charlotte

Posting Permissions

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