VB2005- how to manage multiple checkbox result

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manius
    New Member
    • Dec 2007
    • 9

    VB2005- how to manage multiple checkbox result

    Hi.

    How do I insert in a db multiple checkbox results? I have 11 checkboxes, so how to do it in one query? Please :P
    Last edited by Killer42; Dec 31 '07, 02:16 AM.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    If you give us some idea of how you're interfacing with the database now, to handle a single value, I'm sure we can help you extend it to store multiple values.

    Comment

    • yaad
      New Member
      • Dec 2007
      • 3

      #3
      If you want to use multiple check boxes then first be sure you are using a control array. After that while inserting data take this reference.

      If you have 11 controls then

      Let check box name be check1
      [CODE=vb]
      For I = 0 To 10
      STRA = STRA & "'" & Check1(I).Capti on & "'" & ","
      Next
      STRA = Mid(STRA, 1, Len(STRA) - 1)
      STRSQL = "INSERT INTO TABLENAME VALUES('RAM','S HYAM'," & STRA & ")"

      CN.Execute STRSQL[/CODE]

      That’s it.
      If you need more, contact me on <Removed by Moderator>
      Last edited by Killer42; Dec 31 '07, 08:35 AM.

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Thanks for that, yaad.

        But please don't post your e-mail address (or anyone else's) in the forum. This is for your protection, from scammers and spammers who may scan the list. If people need to contact you privately, they can send you a private message, or "PM" by clicking on your ID to get to your profile. You can then exchange details privately.

        Also, please don't SHOUT when responding to a question. I have converted most of the ALL UPPER CASE TEXT to mixed (or "sentence") case.
        Last edited by Killer42; Dec 31 '07, 08:37 AM.

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Oh, and one more thing. Control arrays were removed after VB6. They're not available in VB 2005. I wish I knew why, as they are an extremely useful feature.

          Comment

          • manius
            New Member
            • Dec 2007
            • 9

            #6
            Control arrays were removed after VB6. >> okay cause I learned 2005 and I don't know what control arrays are :( . You said to show you how my database is? Well I have one table with 2 text fields, 11 checkboxes and 1 datetime field. All of that I should fill with one button click. In text box I enter the name, I select the date and check specific checkbox so I enter the name, date and value for some of the 11 check box like true.
            Last edited by Killer42; Jan 1 '08, 10:56 AM.

            Comment

            • manius
              New Member
              • Dec 2007
              • 9

              #7
              i decide to insert values of all checkboxes at once into table with yes/no field. the questione is how code looks for checkbox control:
              "checbox.______ __???"

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                Originally posted by manius
                ... questione is how code looks for checkbox control:
                "checbox.______ __???"
                Not sure what code you mean. Do you mean how to insert a checkbox value into SQL to go into a Yes/No field? If so, that's probably quite version-specific. In VB6, I would use the Format() function to format the boolean value as "YES" or "NO".

                Comment

                • manius
                  New Member
                  • Dec 2007
                  • 9

                  #9
                  so bad im new so probably i not good explaining, look, i have checkbox on my form, and i want save the users choice or selection, or that checked unchecked value of the checkbox into access database into yes/no table field. it should be quite simple, something like "checbox.checke d" or i dont know????:(

                  Comment

                  • manius
                    New Member
                    • Dec 2007
                    • 9

                    #10
                    Dim sql As String = "insert into dnEvidencija (elektroth) values"
                    & "("+cbElektro.C hecked + ")"

                    this is how it looks in code, it not vorking :(

                    Comment

                    • Torgg
                      New Member
                      • Dec 2007
                      • 41

                      #11
                      This should do it for you

                      Code:
                                  Dim sql As String = "INSERT INTO dnEvidencija " & _
                                    "(Field_One, Field_Two, Field_Three, Field_Four, Field_Five) Values (" & CheckBox1.Checked & "," & CheckBox2.Checked & "," & CheckBox3.Checked & "," & CheckBox4.Checked & "," & CheckBox5.Checked & ");"

                      Hope this helps,
                      Torgg

                      Comment

                      • Killer42
                        Recognized Expert Expert
                        • Oct 2006
                        • 8429

                        #12
                        Just out of curiosity, what do you actually get when you assign the Checked property to a string?

                        Comment

                        • manius
                          New Member
                          • Dec 2007
                          • 9

                          #13
                          Conversion from string "(" to type 'Double' is not valid.

                          Comment

                          • Torgg
                            New Member
                            • Dec 2007
                            • 41

                            #14
                            Originally posted by manius
                            Conversion from string "(" to type 'Double' is not valid.
                            You'll need to post more information then this. Are you getting an error from the code I posted (I tested it and it worked fine)? Did you copy and paste what I posted (just to have a base line of working code)? Please post the modified SQL query you’re having trouble with.

                            Torgg

                            Comment

                            • Killer42
                              Recognized Expert Expert
                              • Oct 2006
                              • 8429

                              #15
                              Originally posted by manius
                              Conversion from string "(" to type 'Double' is not valid.
                              This can't be in response to what I asked, because that was about converting to a string, not from.

                              Comment

                              Working...