<%
'**********************
'Variable Declarations
'Setting up Objects
'**********************
Dim myRS, objConn, connString, maxfields, strSQL, oField, nameExists, oRecordset
connString = Server.MapPath("misc.mdb")
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & connString
Set rsAdd = Server.CreateObject("ADODB.Recordset")
maxfields = Request.Form("NoOfPpl")
%>
<%
'**********************
'Check if form field exists in database table and alter table to add new fields (notes1, notes2, notes3 etc)
'**********************
dbname = "misc.mdb"
tablename = "LUReview"
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;data source="
ConnStr = ConnStr & server.mappath(dbname)
set adoxConn = CreateObject("ADOX.Catalog")
set adodbConn = CreateObject("ADODB.Connection")
adodbConn.open ConnStr
adoxConn.activeConnection = adodbConn
set table = adoxConn.Tables(tablename)
'nameExists = False
Set oRecordset = adodbConn.Execute("SELECT TOP 1 * FROM LUReview")
For Each oField In table.columns
nameExists = False
if left(oField.Name,4) = "Name" Then
for i = 1 to maxfields
If oField.Name = Request.Form("Name" & i) Then nameExists = True
Exit for
End If
if nameExists = False Then
adodbConn.Execute("ALTER TABLE LUReview ADD COLUMN notes" & i & " TEXT(50);")
end if
next
end if
next
set table = nothing
adodbConn.close: set adodbConn = nothing
set adoxConn = nothing
%>
<%
'**********************
'Insert form field values in the columns/fields of table
'**********************
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & connString
Set rsAdd = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT LUReview.* FROM LUReview;"
rsAdd.CursorType = 2
rsAdd.LockType = 3
rsAdd.Open strSQL, objConn
rsAdd.AddNew
for I = 1 to maxfields
rsAdd.Fields("notes" & i & "") = Request.Form("Name" & i & "")
next
rsAdd.Update
rsAdd.Close
Set rsAdd = Nothing
Set objConn = Nothing
Response.Write "Values successfully added."
%>