Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check boxes

Status
Not open for further replies.

ltleforge

Technical User
Oct 11, 2003
7
0
0
GB
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?
 
I am having trouble writing the values to update the database. My form is on a .htm page which sends the data to an asp page.
 
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=&quot;checkbox&quot; name=&quot;chkMe&quot; value=&quot;Yes&quot;>
If I check this box it will send the string value &quot;Yes&quot; to the ASP page. To retrieve this value:
If request.form(&quot;chkMe&quot;) <> &quot;&quot; then
chkMe=request.form(&quot;chkMe&quot;)
Else
chkMe=&quot;No&quot;
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 &quot;No&quot; 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(&quot;ADODB.CONNECTION&quot;)
conn.open YourConnectionSTring
strSql=&quot;Insert INTO tbl_YourTable (YourColumnName) &quot; _
VALUES('&quot; & chkMe & &quot;')&quot;
conn.execute(strSql)
conn.close
set conn=nothing

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top