Results 1 to 11 of 11

Thread: Check Boxes

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2012
    Location
    Ireland
    Posts
    76

    Question Check Boxes

    Hi

    I have a check box on a form and if it is checked i want to insert "yes" into my database and if it is not checked i want to insert "No".


    Does anyone have any ideas on how to do this?

    Thanks

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Check Boxes

    Have a look at the attachment here.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2012
    Location
    Ireland
    Posts
    76

    Re: Check Boxes

    thanks. I am still unsure how to insert the yes or no into my database in the insert statement.

  4. #4
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: Check Boxes

    What kind of database? Do you have the basics set up already, mainly have you connected to it in your program? What is your skill level in this area? If you are just starting out there are plenty of links at this forum to use as eamples.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2012
    Location
    Ireland
    Posts
    76

    Re: Check Boxes

    I have had a look at some examples.

    Yes, i have the database connected and working. I am quite new to VB.

    I have started writing this

    Code:
    Dim apply As String
    
    if chkApply.Value=1 then
    apply="yes" 
    else
    apply="no"
    
    "insert into details (id, name, address, apply) values ( " & txtId.text & "," & txtName.text & "," & apply & ")"

    should it be something along these lines?

  6. #6
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: Check Boxes

    As purely syntax that approach that looks good. I imagine you need quotes around the text fields. You didn't mention what database but MS SQL will accept quotes aroung the ID which I'm guessing is numeric. You don't have address in the values and that will cause errors. Then there is where in the program you want it, is it always and insert or sometimes an update, things like that. You need to be more specific:

    Code:
    "insert into details (id, name, address, apply) values ('" & txtId.Text & "', '" & txtName.Text & "', ' & txtAddress.Text & " ',' " & apply & "')"
    You need an end if too:

    Code:
    if chkApply.Value=1 then
        apply="yes" 
    else
        apply="no"
    end if
    The click event would be a good place if it should only happen there:

    Code:
    Private Sub Apply_Click()
        'your logic here
    End Sub
    Last edited by TysonLPrice; Jan 21st, 2013 at 07:31 AM.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2012
    Location
    Ireland
    Posts
    76

    Re: Check Boxes

    it is mySQL

    It is just when the user presses the ok button the insert should be made into the database.Everything works as i want it to just need to add the check box value into the insert.

    Thanks.

  8. #8
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: Check Boxes

    Well it looks like you have it then unless I'm missing something:

    Code:
    if chkApply.Value=1 then
        apply="yes" 
    else
        apply="no"
    end if
    ' Then your insert.

  9. #9
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Check Boxes

    Assuming of course that your data field is a a text type. I can't remember what field types are in mySql. If it is a Yes/No field or a boolean field then the value would have to be True or False rather than "Yes" or "No"

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Nov 2012
    Location
    Ireland
    Posts
    76

    Re: Check Boxes

    I have this working now. Thanks for all the help

  11. #11
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: Check Boxes

    CM...please mark as RESOLVED.....thx

Tags for this Thread

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