I am trying to find a solution to put checkboxes in a form that update a access database using vbscript. I have tried everything I know can anyone help?
Could you be a little more specific about the problem? Are you unable to add checkboxes to the form or are you unable to write the checkbox values to the database?
First off you will only receive a value if the checkbox is checked. If it is not checked then nothing will hit the asp page. Second, the value that you receive depends on what you enter as the value in your Input tag:
<input type="checkbox" name="chkMe" value="Yes">
If I check this box it will send the string value "Yes" to the ASP page. To retrieve this value:
If request.form("chkMe" <> "" then
chkMe=request.form("chkMe"
Else
chkMe="No"
End IF
I checked for a value from the object chkMe. If I got one I assigned it to a variable (chkMe). If a value didn't come over then I know that the checkbox wasn't checked so I assigned the value "No" to the variable chkMe. If you're writing checkbox (radio buttons too) values to a database you always need to account for the fact that they might not be checked otherwise your SQL statement will blow up.
Now I can use the following code to commit the checkbox value to the db:
Code:
set conn=server.createobject("ADODB.CONNECTION")
conn.open YourConnectionSTring
strSql="Insert INTO tbl_YourTable (YourColumnName) " _
VALUES('" & chkMe & "')"
conn.execute(strSql)
conn.close
set conn=nothing
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.