Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert record.

Status
Not open for further replies.

dasphatman

Programmer
May 26, 2005
6
DK
Is it possible when you insert a record in a database to only insert max 5 records. Can i make it delete the oldest one when i want to insert record #6 and so on?
 
yes.

The process:
1. Pass a count query for the table. If it is greater than
5 then delete the first record.
2. Insert the latest record.

Known is handfull, Unknown is worldfull
 
I have tryid this, but it wont work. Cant seem to see the problem. Can you?

<%
function SQLlize(vStr)
vStr = TRIM(vStr)
vStr = Replace (vStr, "'", "''")
sStr = replace(sStr,"'", "´")
SQLLize = vStr
end function

'ON ERROR RESUME NEXT

Application("Connectionstring") = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & _
Server.MapPath("../db/my_db_test.mdb")
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open Application("Connectionstring")
strSQL = "SELECT * FROM tblUpdate"
Conn.Execute (strSQL)

If Conn.recordcount > 5 Then
strSQL = "DELETE * FROM tblUpdate WHERE Date IN(SELECT TOP 1 Date FROM tblUpdate ORDER BY Date)"
End If

strSQL = "INSERT INTO tblUpdate ( Name, Message ) VALUES (" & _
"'" & sqllize(Request("User")) & "', '" & sqllize(Request("Tell")) & "')"
conn.Execute (strSQL)
conn.Close
%>
 
If Conn.recordcount > 5 Then
strSQL = "DELETE * FROM tblUpdate WHERE Date IN(SELECT TOP 1 Date FROM tblUpdate ORDER BY Date)"
End If


RecordCount is there only for Recordsets...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top