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 (" &
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
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 (" &
& "," & intNOz & "," & intMAYBEz & ")"arrayQuestionID(i) & "," & intCompanyID & "," & intYESz
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