Dynamic checkboxes & INSERT into DB

F

Frank Collins

Can anyone point me to some good examples on the web of
using values from dynamically created checkboxes on forms
in ASP, particularly relating to INSERTING those values
into a SQL or Access database?

Basically, I have a form on which I have a series of
statements, with 3 checkboxes for each statement - YES,
NO, MAYBE. This series of statements is being dynamically
populated from a query of a table in Access,
called "tblQuestions". In the form, I created a hidden
field named "QuestionID" to return the QuestionID. The
checkboxes are named YESz, NOz, and MAYBEz, and set to
return a value of "ON" if checked.

I created another table called "tblQuestionAnswers" into
which I want to insert records, in which I have 6 fields -
1) QAID - an autonumber primary index field, 2)
QuestionID, 3) CompanyID, 4) YesZ, 5) NOz, 6) MAYBEz - the
z is used to reduce the risk of complications from any
reserved fields.

In my update ASP code page, I defined the variables from
the form, and set 3 IF/THEN statements to resolve any NULL
issues with the checkboxes:

IF(IsNull(Request.Form("YESz"))) Then
YESz = 0
Else
YESz = 1
End IF

Etc., for all 3 checkboxes.

Then I tried to create an array and a database connection
to INSERT:

Dim arrayQuestionID
Dim arrayCompanyID
Dim arrayYESz
Dim arrayNOz
Dim arrayMAYBEz
Dim i

arrayQuestionID = split(QuestionID,",")
arrayCompanyID - split(CompanyID,",")
arrayYESz = split(YESz,",")
arrayNOz = split(NOz,",")
arrayMAYBEz = split(MAYBEz,",")

for i = 0 to ubound(arrayQuestionID)
intCompanyID = arrayCompanyID(i)
intYESz = arrayYESz(i)
intNOz = arrayNOz(i)
intMAYBEz = arrayMAYBEz(i)

set myConn=Server.CreateObject("adodb.connection")
myConn.Open "DB"
myConn.Execute "INSERT INTO tblQuestionAnswers
(QuestionID,CompanyID,YESz,NOz,MAYBEz) VALUES (" &
arrayQuestionID(i) & "," & intCompanyID & "," & intYESz
& "," & intNOz & "," & intMAYBEz & ")"
intCompanyID(i)
intSvcOffering(i)
intSvcExemplary(i)
intSvcInterested(i)
Next
myConn.Close
set myConn = Nothing

Basically, I'm now getting a type mismatch error during
the INSERT process. At other times, trying other things, I
have gotten a "Subscript out of range" error. And I'm not
really sure that the thing is iterating over the array,or
if I have the array properly written.

Obviously, I have failed to do something properly! LOL
I've been stuck on this issue for 3 days. Any help that
anyone can give me will be GREATLY APPRECIATED! LOL

"I am an ASP newbie, therefore an ASP ignoramus!" LOL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top