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
Printable View
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
Have a look at the attachment here.
thanks. I am still unsure how to insert the yes or no into my database in the insert statement.
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.
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?
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:
You need an end if too:Code:"insert into details (id, name, address, apply) values ('" & txtId.Text & "', '" & txtName.Text & "', ' & txtAddress.Text & " ',' " & apply & "')"
The click event would be a good place if it should only happen there:Code:if chkApply.Value=1 then
apply="yes"
else
apply="no"
end if
Code:Private Sub Apply_Click()
'your logic here
End Sub
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.
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.
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"
I have this working now. Thanks for all the help :)
CM...please mark as RESOLVED.....thx