title: How to delete a specific record from an access database with asp?
body: <p>So I have a page called BrowseAllItems.asp which displays all my database information along with individual edit buttons that redirect to EditItem.asp (partially shown below) for the option of either editing or deleting the database info for that specific record. The part of editing the data works fine, but I could use some help with deleting the record. Here is what I have:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Sub DeleteRecord
  
  ItemCode=request.form("item_code")
  
  
  'Create an ADO connection object
  Dim Connection
  Set Connection = Server.CreateObject("ADODB.Connection")
  
  'To open an Access database our string would look like the following:
  Dim ConnectionString
  ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)};" &amp;_
                  "DBQ=" &amp; Server.MapPath("\") &amp; "\" &amp; FolderName &amp; "\items.mdb;DefaultDir=;UID=;PWD=;"
  
  'Then to open the database we (optionally) set some of the properties of the Connection and call Open
  Connection.ConnectionTimeout = 30
  Connection.CommandTimeout = 80
  Connection.Open ConnectionString
  
  'Create an ADO recordset object
  Dim rs
  Set rs = Server.CreateObject("ADODB.Recordset")
  
  'Initialise the strSQL variable with an SQL statement to query the database
  strSQL = "SELECT * FROM items WHERE ITEM_CODE='" &amp; ItemCode &amp; "' "
  </code></pre>
  
  <p>I know it has to do with the above line -- This code works if I replace "ItemCode" with the actual item code for the record but I need a way to take the item code from the selected record and apply it where it says ItemCode.</p>
  
  <pre class="lang-vb prettyprint-override"><code>rs.LockType = 3
  'Open the recordset with the SQL query
  rs.Open strSQL, Connection
  'Tell the recordset we are deleting a record 
  rs.Delete 
  
  rs.Close
  'Reset server objects
  Set rs = Nothing
  Set Connection = Nothing
  
  Response.Write "Record Deleted"
  
  End Sub   
  </code></pre>