Results 1 to 6 of 6
  1. #1
    redekopp is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108

    Checkboxes with specific If statements

    Hi there I was wanting to do a code where my checkboxes will react to checkbox 1, in this purpose I have 4 checkboxes, if check1 is true then I want 2,3,4 true as well no exceptions. if check1 is false I want it so that 2,3,4 have to be selected, at least one of them.

    how do I accomplish this with an If statement?
    Code:
    If Me.Check1 = True Then
    Me.Check2 = True
    Me.Check3 = True
    Me.Check4 = True
    End If
    If Me.Check1 = False Then
    Me.Check2 = False
    Me.Check3 = False
    Me.Check4 = False
    End If
    for some reason that did nothing for me.
    and I don't think the false one is correct because I should be able to select 2 3 or 4. or two of them.



    any help would be great 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
    53,770
    If 2, 3, or 4 are already checked, why would you need to set to false?

    If you want to make sure at least one of these is selected when 1 is false before user leaves record, that is data validation and is most often done with code in the form BeforeUpdate event:

    If Me.Check1 = False And Me.Check2 = False And Me.Check3 = False And Me.Check4 = False Then
    MsgBox "Must select at least 1 checkbox."
    Cancel = True
    End If
    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
    redekopp is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108
    Quote Originally Posted by June7 View Post
    If 2, 3, or 4 are already checked, why would you need to set to false?

    If you want to make sure at least one of these is selected when 1 is false before user leaves record, that is data validation and is most often done with code in the form BeforeUpdate event:

    If Me.Check1 = False And Me.Check2 = False And Me.Check3 = False And Me.Check4 = False Then
    MsgBox "Must select at least 1 checkbox."
    Cancel = True
    End If
    Ive mainly got what ive wanted. thanks for that. The only other thing I cant seem to vba right is that if 2,3,4 = true then 1 = true

    I tried this but it wont work;
    Code:
    If Me.eyes = True And Me.frame = True And Me.blurry = True Then
    Me.clear = True
    End If
    is that the right code? I just put that as a general function, maybe im placing it wrong??

    thank you.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    What is purpose of Check1? Why is it even needed?

    So if 2, 3, 4 all are True then 1 must be True?

    Try putting that code in BeforeUpdate event as well.
    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
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    Wanna know a neat trick? Watch this:

    Me.Check2 = Me.Check1
    Me.Check3 = Me.Check1
    Me.Check4 = Me.Check1

    No need for an if statement. ;-)

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by redekopp View Post
    Hi there I was wanting to do a code where my checkboxes will react to checkbox 1, in this purpose I have 4 checkboxes, if check1 is true then I want 2,3,4 true as well no exceptions. if check1 is false I want it so that 2,3,4 have to be selected, at least one of them...
    In addition to applying data validation as suggested by June7, I would probably employ the enabled property for those options that are children to Check1.

    Code:
    If Me.Check1 = True Then
        Me.Check2 = True
        Me.Check3 = True
        Me.Check4 = True
        
        Me.Check2.Enabled = False
        Me.Check3.Enabled = False
        Me.Check4.Enabled = False
    Else
        Me.Check2.Enabled = True
        Me.Check3.Enabled = True
        Me.Check4.Enabled = True
    End If

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

Similar Threads

  1. Replies: 1
    Last Post: 10-08-2015, 04:27 AM
  2. Replies: 1
    Last Post: 11-20-2014, 08:34 AM
  3. Replies: 1
    Last Post: 11-09-2012, 10:45 AM
  4. Replies: 3
    Last Post: 08-22-2012, 09:23 AM
  5. Replies: 1
    Last Post: 06-15-2012, 05:51 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