I would use this:
Code:
<%
on error resume next
Dim Connection
Set Connection = Server.CreateObject("ADODB.Connection")
Connection.Open "testdsn"
Dim Recordset
Set Recordset = Server.CreateObject("ADODB.Recordset")
Recordset.Open "SELECT * FROM Table", Connection, 2, 2
IF Request.Querystring("action") = "Insert" THEN
Recordset.addnew
Recordset("Field1") = Request.Form("Field1")
Recordset("Field2") = Request.Form("Field2")
Recordset("Field3") = Request.Form("Field3")
Recordset.update
Recordset.Close
Recordset.Open "SELECT * FROM Table WHERE Field1 = '" & Request.Form("Field1") & "' AND Field2 = '" & Request.Form("Field2") & "'", Connection, 2, 2
IF Recordset.EOF THEN
Recordset.Close
Set Recordset = Nothing
Connection.Close
Set Connection = Nothing
redirect_string = "?error=Insert_Failed"
For each item in Request.Form
redirect_string = redirect_string & "&" & item & "=" & request.form(item)
Loop
Response.Redirect "insert_page.asp" & redirect_string
else
Success_id = Recordset("ID")
Recordset.Close
Set Recordset = Nothing
Connection.Close
Set Connection = Nothing
response.redirect "successfulinsert.asp?ID=" & Success_id
end if
END IF
%>
Hasn't been tested, but what this should do, is first try to insert what you want to insert, then call it back using the form data that was meant to be inserted, if it doesn't find a record, then it will redirect back the page that sent it with the form data in querystrings, so you can call the info into those field for editting.
If it is successful, then it will redirect to a success page with a insert id, in which you can either review the entered information, or push comes to shove you can remove the id from the response.redirect and get it to show a success message.
Apart from that?
What else can you ask for?
Gav
Bookmarks