I try to add a new record into my Access table (OBJECT ), but somehow it didn’t work. The table that I tried to add into has a one to many relationship with another table (LESSON), where LESSON table is one and OBJECT is many. Does that mean I have to reference or write out a join SQL statement to join the tables in my ASP page in order for it to add.
When I delete the relationship, it added okay. But once I connect the table back, the page doesn’t run. Here is my code, and I hope somebody can help me with it. Thank you!!!
<%
Option Explicit
Dim strConnect
%>
<html>
<head>
<title> Add Record </title>
</head>
<body>
<%
Dim objRS, intObjectID, objConn
Dim adOpenDynamic, adLockOptimistic, adCmdTable
adOpenDynamic = 2
adLockOptimistic = 3
adCmdTable = 2
Set objConn = Server.CreateObject ("ADODB.Connection"
Set objRS = Server.CreateObject ("ADODB.Recordset"
strConnect = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/db/database.mdb"
&";" &_
"Persist Security Info = False"
objConn.Open(strConnect)
objRS.open "OBJECT", objConn, 2, 3, 2
objRS.MoveLast
intObjectID = ObjRS ("ObjectID"
+ 1
objRS.AddNew
objRS ("ObjectID"
= intObjectID
objRS ("Entry"
= Request.Form("entry"
objRS ("Title"
= Request.Form("title"
objRS ("Language"
= Request.Form("language"
objRS ("Description"
= Request.Form("description"
objRS ("Version"
= Request.Form("version"
objRS ("Status"
= Request.Form("status"
objRS ("Date"
= Request.Form("date"
objRS ("Format"
= Request.Form("format"
objRS ("Duration"
= Request.Form("duration"
objRS ("InteractivityLevel"
= Request.Form("interactivityLevel"
objRS ("EndUserSpecification"
= Request.Form("endUser"
objRS ("Difficulty"
= Request.Form("difficulty"
objRS ("Copyright"
= Request.Form("copyright"
objRS ("Annotation"
= Request.Form("comment"
objRS ("Taxon"
= Request.Form ("taxon"
objRS ("LessonID"
= Request.Form("lessonID"
objRS ("LearningObjectiveID"
= Request.Form("objective"
objRS ("AuthorID"
= Request.Form("authorID"
objRS.Update
objRS.Close
objConn.Close
Set objRS = Nothing
Set objConn = Nothing
Response. Redirect "/index.html"
%>
</body>
</html>
When I delete the relationship, it added okay. But once I connect the table back, the page doesn’t run. Here is my code, and I hope somebody can help me with it. Thank you!!!
<%
Option Explicit
Dim strConnect
%>
<html>
<head>
<title> Add Record </title>
</head>
<body>
<%
Dim objRS, intObjectID, objConn
Dim adOpenDynamic, adLockOptimistic, adCmdTable
adOpenDynamic = 2
adLockOptimistic = 3
adCmdTable = 2
Set objConn = Server.CreateObject ("ADODB.Connection"
Set objRS = Server.CreateObject ("ADODB.Recordset"
strConnect = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/db/database.mdb"
"Persist Security Info = False"
objConn.Open(strConnect)
objRS.open "OBJECT", objConn, 2, 3, 2
objRS.MoveLast
intObjectID = ObjRS ("ObjectID"
objRS.AddNew
objRS ("ObjectID"
objRS ("Entry"
objRS ("Title"
objRS ("Language"
objRS ("Description"
objRS ("Version"
objRS ("Status"
objRS ("Date"
objRS ("Format"
objRS ("Duration"
objRS ("InteractivityLevel"
objRS ("EndUserSpecification"
objRS ("Difficulty"
objRS ("Copyright"
objRS ("Annotation"
objRS ("Taxon"
objRS ("LessonID"
objRS ("LearningObjectiveID"
objRS ("AuthorID"
objRS.Update
objRS.Close
objConn.Close
Set objRS = Nothing
Set objConn = Nothing
Response. Redirect "/index.html"
%>
</body>
</html>