Results 1 to 4 of 4

Thread: Validating Multiple checkboxes

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    4

    Validating Multiple checkboxes

    Well let me begin by informing you I am relatively new to access with only a basic understanding of vba.

    Ok well I have a form with 4 checkboxes (chb1,chb2,... representing 4 call centers). The idea is to run a report based on the selections. i.e. only one box selected run report based off that callcenter, 1,3,and 4 selected run the report for those 3, etc.

    I have been scouring around and the examples I have found so far deal with checking only one box and running some action. With the 4 boxes I have 15 combinations of queries and reports including one for all the above.

    I'm looking for suggestions/examples to achieve this. Any help you could give me would be a huge help.

    Thanks in advance,

    -Brian C.

  2. #2

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    4

    Re: Validating Multiple checkboxes

    Got it -
    Terry in the dotnet.vb newsgroup gave this suggestion:

    dim c as integer = 0
    if cbox3.Checked = True then c = 1
    if cbox2.Checked = True then c += 2
    if cbox1.Checked = True then c+=4

    Select Case c
    Case 0 'No checks
    Case 1 'cbox 3
    Case 2 'cbox 2
    Case 3 'cbox 2 & 3
    Case 4 'cbox 1
    Case 5 'cbox 1 & 3
    Case 6 'cbox 1 & 2
    Case 7 'cbox 1,2, & 3
    End Select

    I just modified for my needs:
    Cbox4=true then c=1
    Cbox3=true then c+=2
    Cbox2=true then c+=4
    Cbox1=true then c+=8

    Select Case C
    Case 0 ‘No Checks
    Case 1 ‘cb 4
    Case 2 ‘cb 3
    Case 3 ‘cb 4,3
    Case 4 ‘cb 2
    Case 5 ‘cb 2,4
    Case 6 ‘cb 2,3
    Case 7 ‘cb 2,3,4
    Case 8 ‘cb 1
    Case 9 ‘cb 1,4
    Case 10 ‘cb 1,3
    Case 11 ‘cb 1,3,4
    Case 12 ‘cb 1,2
    Case 13 ‘cb 1,2,4
    Case 14 ‘cb 1,2,3
    Case 15 ‘cb 1,2,3,4
    Thats all I needed maybe this will help someone else. Later

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    4

    Re: Validating Multiple checkboxes

    Problem, MS vba editor will not accept ...then c+=2. Its rejecting the addition operator, saying it expects to see an expression there. any thoughts?

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    4

    Re: Validating Multiple checkboxes

    Again answering my own question, just played with the code a bit:

    Private Sub CmdGenerateReport_Click()
    Dim a As Integer
    Dim b As Integer
    Dim c As Integer
    Dim d As Integer
    If ChbAPACCentral = True Then d = 1
    If ChbCentral = True Then c = 2
    If ChbPD = True Then b = 4
    If Chb4SB = True Then a = 8

    Select Case a + b + c + d
    Case 0
    MsgBox "Please Select Region" _
    & vbCrLf & "Please try again.", vbExclamation, _
    "More information required."
    Case 1
    DoCmd.OpenForm "DRACEForm", acNormal
    DoCmd.Close acForm, "FINALDailyTotalsRegionSelectorForm"
    Case 2
    DoCmd.OpenForm "DRCEForm", acNormal
    DoCmd.Close acForm, "FINALDailyTotalsRegionSelectorForm"
    Case 3
    DoCmd.OpenForm "DRCE,ACEForm", acNormal
    DoCmd.Close acForm, "FINALDailyTotalsRegionSelectorForm"
    Case 4
    DoCmd.OpenForm "DRPDForm", acNormal
    DoCmd.Close acForm, "FINALDailyTotalsRegionSelectorForm"
    Case 5
    DoCmd.OpenForm "DRPD,ACEForm", acNormal
    DoCmd.Close acForm, "FINALDailyTotalsRegionSelectorForm"
    Case 6
    DoCmd.OpenForm "DRPD,CEForm", acNormal
    DoCmd.Close acForm, "FINALDailyTotalsRegionSelectorForm"
    Case 7
    DoCmd.OpenForm "DRPD,CE,ACEForm", acNormal
    DoCmd.Close acForm, "FINALDailyTotalsRegionSelectorForm"
    Case 8
    DoCmd.OpenForm "DR4SBForm", acNormal
    DoCmd.Close acForm, "FINALDailyTotalsRegionSelectorForm"
    Case 9
    DoCmd.OpenForm "DR4SB,ACEForm", acNormal
    DoCmd.Close acForm, "FINALDailyTotalsRegionSelectorForm"
    Case 10
    DoCmd.OpenForm "DR4SB,CEForm", acNormal
    DoCmd.Close acForm, "FINALDailyTotalsRegionSelectorForm"
    Case 11
    DoCmd.OpenForm "DR4SB,CE,ACEForm", acNormal
    DoCmd.Close acForm, "FINALDailyTotalsRegionSelectorForm"
    Case 12
    DoCmd.OpenForm "DR4SB,PDForm", acNormal
    DoCmd.Close acForm, "FINALDailyTotalsRegionSelectorForm"
    Case 13
    DoCmd.OpenForm "DR4SB,PD,ACEForm", acNormal
    DoCmd.Close acForm, "FINALDailyTotalsRegionSelectorForm"
    Case 14
    DoCmd.OpenForm "DR4SB,PD,CEForm", acNormal
    DoCmd.Close acForm, "FINALDailyTotalsRegionSelectorForm"
    Case 15
    DoCmd.OpenForm "DateRangeForm", acNormal
    DoCmd.Close acForm, "FINALDailyTotalsRegionSelectorForm"

    End Select



    End Sub

Posting Permissions

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



Click Here to Expand Forum to Full Width