The following example is the code on how to update or edit a record. The code will also check to see if the record already exists. It the record does not already exist, a new record will be added.
File: update.asp
<%
<!--#include file="adovbs.inc"-->
TEMP = Request.form("Name")
Set DataConn = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.RecordSet")
DataConn.Open "DBQ=" & Server.Mappath("cdemo.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"
' Note: To keep the example simple I update ALL RECORDS with the name that
' is entered in the text box. This is OK for this example since you will not
' (?) allow duplicates. In the real world you would assign a unique ID# to
' each record (access can do this for you).
Set rsInfo = DataConn.Execute("SELECT * FROM tblContact WHERE Name = '" & TEMP & "'")
If rsInfo.EOF Then
SQL = "INSERT INTO tblContact"
SQL = SQL + " (Name, Email, Phone) VALUES ('" & Request("Name") & "', '" & Request("Email") & "', '" & Request.Form("Phone") & "');"
Set rsInfo = DataConn.Execute(SQL)
Response.Write "<CENTER>Record Updated!<br>"
Else
SQL = "UPDATE tblContact"
SQL = SQL + " SET Name = '" & Request("Name") & "', Email= '" & Request("Email") & "', Phone= '" & Request.Form("Phone") & "'"
SQL = SQL + " WHERE Name = '" & TEMP & "';"
Set rsInfo = DataConn.Execute(SQL)
RS.Close
DataConn.Close
Response.Write "<CENTER>Record Updated!<br></CENTER>"
End If
%>