Question Add new record to database

mattg777

New member
Local time
Today, 10:44
Joined
Apr 19, 2011
Messages
2
Hi folks,

I'm fairly new to all this asp, access databases etc. However i've been working away on a shop information program. I can update values in a table, but i can't get it to add a new record. It just replaces the existing record. Can anyone help? Apologises if this is rather trivial, but i'm quite stuck.

Matt.

Here's the part of my code:-


<%
Dim name, month, week
Dim rs, conn


ConnectionString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & "Data Source= c:\inetpub\wwwroot\TimeTracker III\db1.mdb"
Set Conn = Server.CreateObject("ADODB.Connection")
conn.open connectionString
Set rs = Server.CreateObject("ADODB.Recordset")


rs.open "SELECT Week FROM wkhrs WHERE Name = '" & Request.Form("Employee") & "'", conn
If rs.EOF Then


ssql = "INSERT INTO wkhrs (Employee, Shop, period, week)"
ssql = ssql & "VALUES"
ssql = ssql & "Name= '" & Request.Form("Employee") & "',"
ssql = ssql & "Shop= '" & Request.Form("Shop") & "',"
ssql = ssql & "month= '" & Request.Form("month") & "',"
ssql = ssql & "Week= '" & Request.Form("week") & "'"
ssql = ssql & " WHERE Name= '" & Request.Form("Employee") & "'"
conn.Execute ssql
on error resume next

if err<>0 then
response.write ("No update permissions!")
else
Response.redirect("real index.asp")
End if
Response.redirect("real index.asp")


else
ssql = "UPDATE wkhrs SET "
ssql = ssql & "Name= '" & Request.Form("Employee") & "',"
ssql = ssql & "month= '" & Request.Form("month") & "',"
ssql = ssql & "Week= '" & Request.Form("week") & "'"
ssql = ssql & " WHERE Name= '" & Request.Form("Employee") & "'"
conn.Execute ssql
on error resume next

if err<>0 then
response.write ("No update permissions!")
else
Response.redirect("real index.asp")
End if
end if
conn.close

Response.Redirect("real index.asp")
%>
 
Last edited:
Meant to say . . . . a new record should be added for an employee, if there is not already a record for that week and month. If there is it should update. Any help much appreciated.
 

Users who are viewing this thread

Back
Top Bottom