multiple checkbox in access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • voroojak
    New Member
    • Feb 2007
    • 92

    multiple checkbox in access

    Hi
    I have a form that there is 3 checkbox in it.
    one or two or all 3 can be selected.
    i want to pass the selected check box to the sql table.
    the problemis when I just choose 1 checkbox then it doesnt go.

    if i just choose year0 then it wont pass

    'year0
    If chk_year0 = True And chk_year1 = False And chk_year_2 = False Then
    rst.Fields("tar get_spb_year_li st") = year0.Caption
    End If


    but if i chose year0 and year1 then it will pass.

    'year 0 and year 1
    If chk_year0 = True And chk_year1 = True And chk_year_2 = False Then
    rst.Fields("tar get_spb_year_li st") = year0.Caption & " " & year1.Caption
    End If



    i would apprecaite any help,

    thanks
  • puppydogbuddy
    Recognized Expert Top Contributor
    • May 2007
    • 1923

    #2
    Try it this way:
    'year0
    If chk_year0 = -1 And nz(chk_year1,0) = 0 And nz(chk_year_2,0 ) = 0 Then
    rst.Fields("tar get_spb_year_li st") = year0.Caption
    End If

    False does not get checked, so it is returning a null. Using the null to zero function converts the nulls to zero with zero being false.

    Comment

    • kstevens
      New Member
      • Mar 2009
      • 74

      #3
      I didnt think that check boxes could contain null data. I thought that they were either true or false, but never null. Can you chek them independantly?
      Code:
      If [chk_year0]= True Then
      If [ck_year1] = False Then
      If [chk_year_2] = False Then
      blah blah blah
      End If
      End If
      End If
      By the way, are the underscores "_" actually in the field name, or are they spaces. I dont know why (probably got treated as a math problem) but when i used a field that was HL2 it wouldnt cooperate properly until I put the brackets "[]" around it (although it was a number field....that was probably why, probably wont affect a yes/no field). If they are spaces, i would put the brakcets around them and use spaces instead of the underscore, just because that is how they were actually written, although someone here might say "they work either way" I just dont like numbers at the end of my field names or the underscores.

      Comment

      • puppydogbuddy
        Recognized Expert Top Contributor
        • May 2007
        • 1923

        #4
        see these links:

        A workaround for a bug where Microsoft Access crashes or fails to execute queries with Yes/No fields.


        Explains why not to use a heap of Yes/No fields in a table to store preferences, and how to use a relational design instead. Example database for Microsoft Access

        Comment

        Working...