Access checkbooks controlled via vba

Posted on 2012-08-26
Last Modified: 2012-08-26
Hello Experts,

I have a continous form with 8 checkboxes. For each record, I want to disable the unchecked checkboxes when the user checks 4 out the 8 checkboxes. How do I do it?

The name of the checkboxes is chk1, chk2, chk3, etc...

Thank you
Question by:fitaliano
    1 Comment
    LVL 39

    Accepted Solution

    You can use this sub:
    Sub chkboxes()
    Dim S As Integer, i As Integer
    S = 0
    For i = 1 To 8
        S = S - Nz(Me("chk" & i), 0)
    Next i
    If S = 4 Then
      For i = 1 To 8
            If IsNull(Me("chk" & i)) Or Me("chk" & i) <> True Then Me("chk" & i).Enabled = False
      Next i
      For i = 1 To 8
        If Me("chk" & i).Enabled = False Then Me("chk" & i).Enabled = True
      Next i
    End If
    End Sub

    Open in new window

    Call it from after update event in all check boxes:
    Private Sub chk1_AfterUpdate()
    End Sub

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    In the article entitled Working with Objects – Part 1 (, you learned the basics of working with objects, properties, methods, and events. In Work…
    Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
    In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
    In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now