Okay...*NOW* it makes more sense to me. Thank you very much for explaining what you are after; it helps tons.
Yes, you *CAN* do all you are asking for, but read again my post #8. The DELETE and INSERT operations:
(a) can be on the same page as the SELECT but need to be *BEFORE* the select, and
(b) they truly are completely independent of the SELECT.
Here is a demo of the ENTIRE concept. It only shows 4 columns of your table, but it shows the important 4 for understanding thins. At the top of the table is one line with form fields to be filled in after which the user hits the "Add" button and that new record gets inserted into the table. On each line showing an existing record, there is a "Delete" button. Click on that and that record gets deleted. After either and "Add" or "Delete"--or just the first time you get to this page--the table contents are dumped to the screen.
Obviously I couldn't actually test this code, since I don't have your database, but I know the concepts are sound, because I've used them many times. If there are bugs, they should be minor typos.
' first make the connection to be used by whatever else happens:
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("myDatabase.mdb")
' now check: Did user request to delete or insert a record?
' delete check:
delrec = Trim(Request("deleteID"))
If delrec <> 0 AND IsNumeric(delrec) Then
sql = "DELETE FROM tblWolf WHERE wolfID = " & CLNG(delrec)
howmany = 0
conn.Execute sql, howmany
If howmany = 0 Then
Response.WRite "?? No wolfID of " & delrec & " found to delete??<hr>"
' insert check:
If Trim(Request("insertRec")) = "YES" Then
' validate all the insert values before accepting the insert!
' I will show just 4 validations...you should validate EVERY field
oops = ""
Set RE = New RegExp
RE.pattern = "[^a-zA-Z]"
RE.global = True
wolfID = Trim(Request("wolfid"))
If Not IsNumeric(wolfID) Then
oops = oops & "<li>wolfID is not a number</li>"
Elseif CDBL(wolfID) <> CLNG(wolfID) OR CLNG(wolfID) <= 0 Then
oops = oops & "<li>wolfID must be an integer greater than zero</li>"
fname = Trim(Request("firstname"))
If Len( RE.replace( fname, "" ) ) < 2 Then
oops = oops & "<li>first name should be at least 2 letters long</li>"
lname = Trim(Request("lastname"))
If Len( RE.replace( lname, "" ) ) < 3 Then
oops = oops & "<li>last name should be at least 3 letters long</li>"
RE.pattern = "[^\d]"
phone = RE.replace( Trim(Request(phone)), "" ) ' zap all but digits of phone
If Len(phone) = 11 AND Left(phone,1) = "1" Then phone = Mid(phone,2) ' zap leading 1 if 11 digits
If Len(phone) <> 10 Then
oops = oops & "<li>phone number must be 10 digits in length</li>"
If oops <> "" Then
Response.Write "Unable to insert that data because:<ul>" & oops & "</ul><hr/>"
' okay to do the insert
' protect against SQL injection and allow apostrophes in names, thus:
fname = Replace( fname, "'", "''")
lname = Replace( lname, "'", "''")
' create the sql:
sql = "INSERT INTO tblWolf( wolfid, firstname, lastname, phone ) " _
& " VALUES( " & wolfID & ",'" & fname & "','" & lname & "','" & phone & "')"
On Error Resume Next
conn.Execute sql ' do the insert
IF Err.Number > 0 Then
Response.Write "Insert failed: " & Err.Description & "<br/>" & sql
Response.End ' abort?
On Error GoTo 0
' *NOW* you are ready to display the current contents of tblWolf to the user.
' But let's make sure there is a line for adding a record:
<table border="1" cellpadding="5">
<input type="hidden" name="insertRec" value="YES" />
<td><input type="submit" value="Add" /></td>
' and now dump out existing records, each with a delete button:
sql = "SELECT * FROM tblWolf ORDER BY lastname, firstname "
Set RS = conn.Execute( sql )
Do Until RS.EOF
wolfid = RS("wolfid")
phone = RS("phone")
' pretty up the phone number:
If Len(phone) = 10 Then phone = "(" & Left(phone,3) & ") " & Mid(phone,4,3) & "-" & Mid(phone,7)
<input type="hidden" name="deleteID" value="<%=wolfid%>" />
<input type="submit" value="Delete" />