Deleting a Record Continued

Results 1 to 2 of 2

Thread: Deleting a Record Continued

  1. #1
    Join Date
    Dec 1969

    Default Deleting a Record Continued

    This is a continuation of a thread from yesterday. I can&#039;t get records to properly delete. I get the error message:<BR><BR>"error &#039;80020009&#039; <BR>Exception occurred. <BR>/x.asp, line 81"<BR><BR>where line 81 is "Do Until objRec.Fields("ID") = RecordToDelete"<BR><BR>from the following code:<BR><BR>(Sorry, I&#039;m very very new to ASP and honestly know even less about SQL statements.)<BR><BR>StrConnect = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=D:wwwroothudson11comDatabasearticles.mdb"<BR>S et objConn = Server.CreateObject ("ADODB.Connection")<BR>objConn.Open StrConnect<BR><BR>Set objRec = Server.CreateObject ("ADODB.Recordset")<BR>objRec.Open "Table1", strConnect, 0,2,2<BR><BR>While NOT objRec.EOF <BR>Response.Write "&#060;b&#062;“" & objRec("Title") & "”&#060;/b&#062;" & ", <BR>" <BR><BR>If objRec("Author")="No byline" then<BR>Response.Write ""<BR>Else<BR>Response.Write "By " & objRec("Author") & " "<BR>End If<BR><BR>Response.Write objRec("Publication") & ", " <BR>Response.Write objRec("PubDate") & ", " <BR>Response.Write objRec("Country") & ", " <BR>Response.Write objRec("Category") & ", "<BR>Response.Write objRec("Deck") & "<BR>" <BR><BR>Response.Write(" &#060;a href=&#039;edit.asp?ID=" & objRec.Fields("ID") & "&#039;&#062;Edit&#060;/a&#062; / &#060;a href=&#039;x.asp?Action=Delete&ID=" & objRec.Fields("ID") & "&#039;&#062;Delete&#060;/a&#062;") & "<BR><BR>" <BR><BR>objRec.MoveNext<BR><BR>If Request.QueryString("Action") = "Delete" Then<BR>If Request.QueryString("ID") &#060;&#062; "" Then <BR><BR>RecordToDelete = CInt(Request.QueryString("ID")) <BR><BR>If Not objRec.BOF Then<BR>objRec.MoveFirst <BR>Do Until objRec.Fields("ID") = RecordToDelete<BR><BR>objRec.MoveNext<BR>Loop <BR><BR>objRec.Delete<BR>objRec.Requery<BR>End If<BR>End If<BR>End If <BR><BR>Wend<BR><BR>objRec.close<BR>Set objRec=nothing<BR>objConn.Close<BR>set objConn=nothing

  2. #2
    Join Date
    Dec 1969

    Default RE: Deleting a Record Continued

    Are you expecting that this ONE SET of code will *both* list the records on the screen *AND* process the user&#039;s request to delete one?<BR><BR>Nope. Can&#039;t do that.<BR><BR>You have to give the user a list of records to delete. They choose one. They submit the form to *OTHER CODE* that deletes a record. [And then, optionally, you can go back and list the remaining records. But that is *NOT* part of the deletion process!]<BR><BR>Might I suggest that you visit and look at the "Database Lessons" there? Especially the "full cycle" example that he gives?<BR><BR>[There are other reasons (in your code) that what you are doing won&#039;t work, but they are largely irrelevant if you are making the mistake I think you are making, as noted above.]<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts