dbertanjoli
Registered User.
- Local time
- Today, 13:09
- Joined
- Sep 22, 2000
- Messages
- 102
I have a questionnaire webform that send data to my access database. In my database I have a few tables: Users (FullName, age, date, medical record), table Questions (stores question number, question answer, iduser) and table results (stores predefined scores for each question/number and idquestions).
You can see from my code that I select Iduser and insert it into table questions. What I am trying to do for last several days is to select newly created idQuestion from table Questions and insert it into table results so we can calculate points for each questionnaire. I am new in ASP and would greatly appreciate if you could help me with this problem.
Here is my code and I just wish to add a peace to insert newly created idQustion to my table results:
<%
' Declaring variables
Dim tmpFullName, tmpAge, tmpDateDB, tmpMedicalRecord, tmpExamOne, tmpExamTwo, data_source, conn, conOne, sql_insert
' Receiving values from Form
tmpName = (Request.Form("FullName"))
tmpAge = (Request.Form("age"))
tmpDateDB = (Request.Form("dateDB"))
tmpMedicalRecord = (Request.Form("MedicalRecord"))
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.connectionstring = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" _
& Server.Mappath("Questions.mdb") & ";"
objConn.Open
SQLstmt = "INSERT INTO users (txtFullName, intAge, txtDateDB, intMedicalRecord)"
SQLstmt = SQLstmt & " VALUES ("
SQLstmt = SQLstmt & "'" & tmpName & "',"
SQLstmt = SQLstmt & "'" & tmpAge & "',"
SQLstmt = SQLstmt & "'" & tmpDateDB & "',"
SQLstmt = SQLstmt & "'" & tmpMedicalRecord & "'"
SQLstmt = SQLstmt & ")"
SET RS = objConn.Execute(SQLstmt)
SQLstmt = "SELECT MAX(idUsers) as MaxUserId FROM Users;"
Set RS=objConn.Execute(SQLstmt)
thisRecord = rs("MaxUserId")
For x = 0 to 30
tmpAnswer = Request.Form("Question" & x)
SQLstmt = "INSERT INTO Questions (idUser, QuestionNumber, QuestionAnswer)"
SQLstmt = SQLstmt & " VALUES ("
SQLstmt = SQLstmt & "'" & thisRecord & "',"
SQLstmt = SQLstmt & "'" & x & "',"
SQLstmt = SQLstmt & "'" & tmpAnswer & "'"
SQLstmt = SQLstmt & ")"
SET RS = objConn.Execute(SQLstmt)
next
objConn.Close
Set objConn = Nothing
Response.Write "All records were successfully entered into the database."
%>
You can see from my code that I select Iduser and insert it into table questions. What I am trying to do for last several days is to select newly created idQuestion from table Questions and insert it into table results so we can calculate points for each questionnaire. I am new in ASP and would greatly appreciate if you could help me with this problem.
Here is my code and I just wish to add a peace to insert newly created idQustion to my table results:
<%
' Declaring variables
Dim tmpFullName, tmpAge, tmpDateDB, tmpMedicalRecord, tmpExamOne, tmpExamTwo, data_source, conn, conOne, sql_insert
' Receiving values from Form
tmpName = (Request.Form("FullName"))
tmpAge = (Request.Form("age"))
tmpDateDB = (Request.Form("dateDB"))
tmpMedicalRecord = (Request.Form("MedicalRecord"))
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.connectionstring = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" _
& Server.Mappath("Questions.mdb") & ";"
objConn.Open
SQLstmt = "INSERT INTO users (txtFullName, intAge, txtDateDB, intMedicalRecord)"
SQLstmt = SQLstmt & " VALUES ("
SQLstmt = SQLstmt & "'" & tmpName & "',"
SQLstmt = SQLstmt & "'" & tmpAge & "',"
SQLstmt = SQLstmt & "'" & tmpDateDB & "',"
SQLstmt = SQLstmt & "'" & tmpMedicalRecord & "'"
SQLstmt = SQLstmt & ")"
SET RS = objConn.Execute(SQLstmt)
SQLstmt = "SELECT MAX(idUsers) as MaxUserId FROM Users;"
Set RS=objConn.Execute(SQLstmt)
thisRecord = rs("MaxUserId")
For x = 0 to 30
tmpAnswer = Request.Form("Question" & x)
SQLstmt = "INSERT INTO Questions (idUser, QuestionNumber, QuestionAnswer)"
SQLstmt = SQLstmt & " VALUES ("
SQLstmt = SQLstmt & "'" & thisRecord & "',"
SQLstmt = SQLstmt & "'" & x & "',"
SQLstmt = SQLstmt & "'" & tmpAnswer & "'"
SQLstmt = SQLstmt & ")"
SET RS = objConn.Execute(SQLstmt)
next
objConn.Close
Set objConn = Nothing
Response.Write "All records were successfully entered into the database."
%>