Hele scriptet ser således ud, denne side både opdatere og opretter en ny:
<%
Dim strSQL
Dim strAutoID
strAutoID=Request.Querystring("AutoID")
If Request.Form("hidSubmitted")<>"" Then
Set oDB = Server.CreateObject("ADODB.connection")
oDB.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../../../db/Staevner_res.mdb")
If Request.Form("hidSubmitted")="New" Then
'Opret ny post
strSQL="INSERT INTO [res] (StaevneNavn,StaevneLink,StaevneBeskr,ResultatNavn,ResultatLink,ResultatBeskr,Dato) VALUES ('"
strSQL=strSQL & Request.Form("txtStaevneNavn")&"','"
strSQL=strSQL & Request.Form("txtStaevneLink")&"','"
strSQL=strSQL & Request.Form("txtStaevneBeskr")&"','"
strSQL=strSQL & Request.Form("txtResultatNavn")&"','"
strSQL=strSQL & Request.Form("txtResultatLink")&"','"
strSQL=strSQL & Request.Form("txtResultatBeskr")&"',"
strSQL=strSQL & Request.Form("txtDato")&"')"
oDB.Execute(strSQL)
strHeadline=Request.Form("txtSwimProfil")
Set oRS = oDB.execute("SELECT AutoID FROM [res] order by AutoID desc")
strAutoID=oRS.Fields("AutoID")
Set oRS = Nothing
Response.write "<b>Stævnet er nu oprettet!</b> <a href='/'>Tilbage til hovedsiden - klik her!</a>"
Else
'Opdater post
strSQL="UPDATE [res] SET "
strSQL=strSQL & "StaevneNavn='" & Request.Form("txtStaevneNavn")&"', "
strSQL=strSQL & "StaevneLink='" & Request.Form("txtStaevneLink")&"', "
strSQL=strSQL & "StaevneBeskr='" & Request.Form("txtStaevneBeskr")&"', "
strSQL=strSQL & "ResultatNavn='" & Request.Form("txtResultatNavn")&"', "
strSQL=strSQL & "ResultatLink='" & Request.Form("txtResultatLink")&"', "
strSQL=strSQL & "ResultatBeskr='" & Request.Form("txtResultatBeskr")&"',"
strSQL=strSQL & "Dato='" & Request.Form("txtDato")&"'WHERE AutoID=" & Request.Form("hidSubmitted")
oDB.Execute(strSQL)
End If
oDB.Close
set oDB = Nothing
End If
If Request.Querystring("Delete")<>"" Then
Set oDB = Server.CreateObject("ADODB.connection")
oDB.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../../../db/staevner_res.mdb")
'Slet post
oDB.Execute("DELETE FROM [res] WHERE AutoID=" & Request.Querystring("Delete"))
oDB.Close
End If
Dim strViewType 'Angiver hvad der skal vises. Afhænger af: om det er første gang man går ind på siden(start), om man har valgt land(land) eller vil oprette ny(ny)
If strAutoID ="NewRecord" Then
strViewType="Ny"
ElseIf strAutoID="" Then
strViewType="Start"
Else
strViewType="Land"
End If
%>
<html>
<head>
<meta http-equiv="Content-Language" content="da">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>RH Admin Stævner/resultater</title>
<SCRIPT LANGUAGE="JavaScript">
function newRec(){
location='default.asp?AutoID=NewRecord'
}
function go(){
var strSwimProfil
strAutoID = document.formSwimProfil.txtSwimProfilGet.options[document.formSwimProfil.txtSwimProfilGet.selectedIndex].value;
location = 'default.asp?AutoID=' + strAutoID
}
function saveMe(){
document.formSwim.submit()
}
function deleteMe(inAutoID){
if (confirm('Er du sikker på at du vil slette dette stævne/resultat?')){
location='default.asp?Delete='+inAutoID;
}
}
</SCRIPT>
</head>
<body>
<div align="center">
<center>
<div align="left">
<table border="0" style="border-collapse: collapse" bordercolor="#111111" cellpadding="0" cellspacing="0">
<tr>
<td colspan="6" height="29">
<%
Set oDB = Server.CreateObject("ADODB.connection")
oDB.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../../../db/staevner_res.mdb")
Set oRS = oDB.execute("SELECT StaevneNavn,AutoID FROM [res] ORDER BY StaevneNavn DESC")
%>
<form name="formSwimProfil" method="get">
<p align="left">
<font face="Verdana">
<select name="txtSwimProfilGet" size="1">
<%
Dim strRSStaevneNavn
Dim strRSAutoID
Dim sel
Do While Not oRS.EOF
strRSAutoID = oRS("AutoID")
if request.querystring("AutoID")<>"NewRecord" then
strRSStaevneNavn = oRS("StaevneNavn")
If strRSAutoID<>Cint(strAutoID) Then
sel=""
else
sel="selected"
end if
end if
%>
<OPTION VALUE="<%= strRSAutoID %>" <%= sel %>><%= strRSStaevneNavn %></OPTION>
<%
oRS.MoveNext
Loop
%>
</select>
<input type="button" name="btnGo" value="<- Hent Stævne/resultat" onclick="java script:go();">
<input type="button" name="btnNew" value="Opret nyt stævne"
onclick="java script:newRec();"></font>
</form>
</td>
</tr>
<%
Set oRS = Nothing
Set oDB = Nothing
%>
<%
If strViewType <>"Start" Then
Set oDB = Server.CreateObject("ADODB.connection")
oDB.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../../../db/staevner_res.mdb")
If strViewType ="Land" Then
Set oRS = oDB.execute("SELECT * FROM [res] WHERE AutoID="&strAutoID&"")
oRS.MoveFirst
strNewsID=oRS.Fields("AutoID")
strStaevneNavn=oRS.Fields("StaevneNavn")
strStaevneLink=oRS.Fields("StaevneLink")
strStaevneBeskr=oRS.Fields("StaevneBeskr")
strResultatNavn=oRS.Fields("ResultatNavn")
strResultatLink=oRS.Fields("ResultatLink")
strResultatBeskr=oRS.Fields("ResultatBeskr")
strDato=oRS.Fields("Dato")
oRS.Close
oDB.Close
Set oRS = Nothing
Set oDB = Nothing
Else
'Vaerdier for ny post
strAutoID="New"
strStaevneNavn=""
strStaevneLink=""
strStaevneBeskr=""
strResualtatNavn=""
strResultatLink=""
strResultatBeskr=""
strDato=""
End If
%>
<%
Set oDB = Server.CreateObject("ADODB.connection")
oDB.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../../../db/Staevner_res.mdb")
%>
</div>
<table style="border-collapse: collapse" bordercolor="#111111" cellpadding="0" width="100%"/>
<tr>
<td width="167" height="15">
</td>
<td width="695" height="15">
</td>
</tr>
<tr>
<td width="167" height="15">
<form name="formSwim" method="post" action="default.asp?AutoID=<%=strAutoID %>">
<font face="Verdana" size="1">
<b>
<input type=hidden name="hidSubmitted" value="<%= strAutoID %>"></b>
</font><b><font face="Verdana" size="1">Auto ID </font></b>
</td>
<td width="695" height="15">
<b>
<font face="Verdana" size="1">
<%=strAutoID %></font></b></td>
</tr>
<tr>
<td width="167" height="25"><b><font face="Verdana" size="1">Dato:</font></b></td>
<td width="370" height="25"><b><font face="Verdana" size="1">
<select size="1" name="txtDato">
<%
for a=-180 to 365
DateVal=formatDateTime(now() + a,2)
if strDato<>"" then
if Cdate(DateVal) = strDato then
sel="selected"
else
sel=""
end if
else
if DateVal=formatDateTime(now(),2) then
sel="selected"
else
sel=""
end if
end if
%>
<option value="<%= DateVal %>"<%= sel %>><%= DateVal %></option>
<%
Next
%>
</select>
(dd-mm-åååå)</font></b></td>
</tr>
<tr>
<td width="167" height="25"><b><font face="Verdana" size="1">Stævnets title:</font></b></td>
<td width="370" height="25"><b><font face="Verdana" size="1">
<input type="text" value="<%= strStaevneNavn %>" name="txtstaevneNavn" size=52></font></b></td>
</tr>
<tr>
<td width="167" height="25"><b><font face="Verdana" size="1">Link til
Stævnet:</font></b></td>
<td width="450" height="25">
<b><font face="Verdana" size="1">
http://<input type="text" value="<%= strStaevneLink %>" name="txtStaevneLink" size="52"></font></b></td>
</tr>
</center>
<tr>
<td width="167" valign="top" height="117">
<p align="left"><b><font face="Verdana" size="1">Ultra kort beskrivelse af
stævnet:</font></b></td>
<center>
<td width="370" valign="top" height="117">
<textarea rows="4" cols="52" rows="4" input type="text" name="txtStaevneBeskr"><%= strStaevneBeskr %></textarea></td>
</tr>
<tr>
<td width="167" height="25"><b><font face="Verdana" size="1">Resultat Title:</font></b></td>
<td width="370" height="25"><b><font face="Verdana" size="1">
<input type="text" value="<%= strResultatNavn %>" name="txtResultatNavn" size=52></font></b></td>
</tr>
<tr>
<td width="167" height="25"><b><font face="Verdana" size="1">Link til
resultatet:</font></b></td>
<td width="450" height="25">
<b><font face="Verdana" size="1">
http://<input type="text" value="<%= strResultatLink %>" name="txtResultatLink" size="52"></font></b></td>
</tr>
<tr>
<td width="167" valign="top" height="71">
<p align="left"><b><font face="Verdana" size="1">Ultra kort beskrivelse af
resultatet:</font></b></td>
<td width="370" valign="top" height="71">
<textarea rows="4" cols="52" rows="4" input type="text" name="txtResultatBeskr"><%= strResultatBeskr %></textarea></td>
</tr>
<tr>
<td width="167" valign="top" height="74"> </td>
<td width="370" valign="top" height="74">
<font face="Arial" size="2" color="#660000"> </font></td>
</tr>
</table>
</center>
</div>
<p align="center"><font face="Verdana" size="2" color="#660000">
<input type="button" name="btnUpUpDated" value="Gem/opdater Stævne/resultat" onclick="java script:saveMe();">
<% If strViewType ="Land" Then%>
<input type="button" name="btnDelete" value="Slet <%= strStaevneNavn %>" onclick="java script:deleteMe('<%= strAutoID %>');">
<%
End If
End If
%>
</font>
</body>
</form>
</html>