Results 1 to 6 of 6
  1. #1
    Sjohnson304 is offline Novice
    Windows XP Access 2007
    Join Date
    May 2013
    Posts
    3

    Post limiting checkboxes


    I am creating an Access form that has 3 separate questions that have multiple responses using checkboxes. The user can choose multiple answers for only one question. I'd like to be able to prevent the user from making a selection from the other two questions.

    In other words, if someone answers Q1 (as many as apply), then they should not be able to answer Q2 or Q3 and so on. Thanks!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Use code that disables Q2 and Q3 if Q1 has data and conversely enables those controls if data removed from Q1. Can't offer specifics because don't know your db.

    Are you using multi-value field? I NEVER use multi-value field.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Sjohnson304 is offline Novice
    Windows XP Access 2007
    Join Date
    May 2013
    Posts
    3

    Database attached -- Limiting Checkboxes

    Please see attached. It's in the "Client Services - p2" form. The question is in the "Vulnerability Risk Factors" box.

    Thanks!
    Attached Files Attached Files

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    So to expand on your earlier statement, if user answers Q2 you want Q1 and Q3 disabled or if Q3 answered disable Q1 and Q2? This code seems to work:
    Code:
    Function SetBoxes()
    Dim booQ1 As Boolean, booQ2 As Boolean, booQ3 As Boolean
    With Me
        booQ1 = .Seeking_an_Abortion Or .Abortion_is_scheduled Or .Abortion_is_scheduled
        booQ2 = .Has_a_medical_condition Or _
            .Has_not_eliminated_Abortion_as_a_possibility Or _
            .Is_pressured_to_abort_or_consider_it Or _
            .Does_not_meet_criteria_for__Likely_to_Carry_ Or _
            .Is_undecided
        booQ3 = .Does_not_believe_in_Abortion Or _
            .Has_significant_support Or _
            .All_indications_reveal_a_healthy_pregnancy Or _
            .Wants_to_get_pregnant
        .Seeking_an_Abortion.Enabled = Not booQ2 And Not booQ3
        .Abortion_is_scheduled.Enabled = Not booQ2 And Not booQ3
        .Abortion_Procedure_has_begun.Enabled = Not booQ2 And Not booQ3
        .Has_a_medical_condition.Enabled = Not booQ1 And Not booQ3
        .Has_not_eliminated_Abortion_as_a_possibility.Enabled = Not booQ1 And Not booQ3
        .Is_pressured_to_abort_or_consider_it.Enabled = Not booQ1 And Not booQ3
        .Does_not_meet_criteria_for__Likely_to_Carry_.Enabled = Not booQ1 And Not booQ3
        .Is_undecided.Enabled = Not booQ1 And Not booQ3
        .Does_not_believe_in_Abortion.Enabled = Not booQ1 And Not booQ2
        .Has_significant_support.Enabled = Not booQ1 And Not booQ2
        .All_indications_reveal_a_healthy_pregnancy.Enabled = Not booQ1 And Not booQ2
        .Wants_to_get_pregnant.Enabled = Not booQ1 And Not booQ2
    End With
    End Function
    In the Click event property of each checkbox: =SetBoxes()

    Can even call the function in the form's Current event property to set the checkboxes for existing records.

    Instead of a long form that requires scrolling, consider organizing the 4 sections onto pages of tab control.

    Advise no spaces or special characters/punctuation (underscore is exception) in names.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Sjohnson304 is offline Novice
    Windows XP Access 2007
    Join Date
    May 2013
    Posts
    3
    WOW!!! This looks amazing! I totally understand where you're going with this. So I'm clear on this . . . I will copy this code and insert it into the "OnClick" event property for each checkbox? Two questions:

    1) If I choose the "..." for the OnClick box, do I choose Macro Builder, Expression Builder, or Code Builder?

    2) Do I insert "=SetBoxes()" above this code in each checkbox?

    I hate to be so ignorant on this process, but I'm a little confused.

    Thanks for all your help! I appreciate so much what you're doing!!!

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    The answer to 1 is NONE (maybe the expression builder but I never use it), the answer to 2 is NO.

    The expression =SetBoxes() goes directly in the Click event property, no macro, no VBA for the Click events. This is a function call.

    The SetBoxes function goes in the form's VBA code module. This is a Function that behaves like a Sub because no value is returned by the Function but Subs can't be called by Access elements.

    That is one way to set this up. The other is to build a macro or VBA event procedure for each checkbox. Then SetBoxes procedure can be a Function or Sub. Call SetBoxes in each event. For VBA like:

    Sub Has_not_eliminated_Abortion_as_a_possibility_Click ()
    Setboxes
    End Sub

    Much easier just to call Function directly from the Click property but do whichever appeals to you.

    You can actually select all the checkboxes at once (hold down the shift as you select each) then type =SetBoxes into Click event for all the selected checkboxes. Voila! Done!

    Unfortunately, calling the procedure from the Current event isn't working. Another quirk of yes/no field and checkbox control. Change names of checkboxes different from the field names they are bound to, like chk1, chk2, etc. Then replace the field names in the code with the checkbox names.
    Last edited by June7; 05-04-2013 at 03:57 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Limiting list box by another field
    By lukebowes in forum Access
    Replies: 15
    Last Post: 05-21-2012, 12:12 AM
  2. Limiting Duplicates
    By Zerdan in forum Forms
    Replies: 4
    Last Post: 06-07-2011, 09:29 AM
  3. Form limiting records
    By yaro.kobzar in forum Programming
    Replies: 1
    Last Post: 05-21-2011, 06:50 AM
  4. limiting amount of records
    By yaro.kobzar in forum Programming
    Replies: 1
    Last Post: 05-17-2011, 07:01 PM
  5. limiting number?
    By vespid in forum Database Design
    Replies: 1
    Last Post: 01-10-2011, 10:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums