PDA

Click to See Complete Forum and Search --> : Deleting Records in Access


artsapimp
Mar 7th, 2001, 01:43 PM
I am having trouble deleting records from an Access database using the following code. There are 2 SQL statements.

1 - Deletes the record indicated in the QueryString
2 - Deletes all records where the length of one field is less than 3

Here's the code

<%
Dim cnn
Dim rst
Dim ConnectString
Dim strSQL
Dim strDelSQL

Set cnn = Server.CreateObject("ADODB.Connection")
Set rst = Server.CreateObject("ADODB.Recordset")

ConnectString = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " & Server.MapPath("database/tickets.mdb")

strSQL = "DELETE * FROM RRS_Tickets WHERE TicketID = " & Request.QueryString("Record")
strDelSQL = "DELETE * FROM Tickets WHERE Len(Ticket_Number) < 3"

cnn.Open ConnectString

rst.Open strDelSQL, cnn, 2, 2
rst.Close

rst.Open strSQL, cnn, 2, 2
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing

Response.Redirect("Tickets.asp")
%>


Here's the error I'm getting

ADODB.Recordset error '800a0e78'

The operation requested by the application is not allowed if the object is closed.

?


Thank you for any help.

dcarlson
Mar 7th, 2001, 01:56 PM
You're pretty close.

use

cnn.execute strDelSQL, , adcmdtext
cnn.execute strSQL, , adcmdtext


instead of

rst.Open strDelSQL, cnn, 2, 2
rst.Close

rst.Open strSQL, cnn, 2, 2
rst.Close

artsapimp
Mar 7th, 2001, 02:03 PM
Thanks. What does the adcmdtext part mean?

dcarlson
Mar 7th, 2001, 02:37 PM
The adcmdtext is optional and means that you are passing a text string to execute the command. If you look in your ADO help, you'll find other options such as adCmdTable, adCmdUnkown...

You can also apply those options when opening a recordset.

artsapimp
Mar 7th, 2001, 02:40 PM
Thank you very much!