|
-
Jan 21st, 2013, 05:14 AM
#1
Thread Starter
Lively Member
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
-
Jan 21st, 2013, 05:23 AM
#2
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
-
Jan 21st, 2013, 05:45 AM
#3
Thread Starter
Lively Member
Re: Check Boxes
thanks. I am still unsure how to insert the yes or no into my database in the insert statement.
-
Jan 21st, 2013, 06:27 AM
#4
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.
-
Jan 21st, 2013, 06:40 AM
#5
Thread Starter
Lively Member
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?
-
Jan 21st, 2013, 07:22 AM
#6
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.
-
Jan 21st, 2013, 08:28 AM
#7
Thread Starter
Lively Member
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.
-
Jan 21st, 2013, 08:37 AM
#8
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.
-
Jan 21st, 2013, 08:44 AM
#9
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"
-
Jan 21st, 2013, 09:45 AM
#10
Thread Starter
Lively Member
Re: Check Boxes
I have this working now. Thanks for all the help
-
Jan 21st, 2013, 01:50 PM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|