Solved

Delete method raises error

Posted on 2004-09-17
6
754 Views
Last Modified: 2008-02-01
I am trying to call the Delete method of the ADOB/Recordset object (ADO 2.1) to delete all the records in the table.
I have tried every CursorType / LockType combination and nothing works.  I have also tried changing the source property to "Select * From FTPFiles" to no avail.  I also get this error when I modify a record and call the Update method.

Depending on the CursorType / LockType combination I get one of the following errors

1. Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype.
2. Operation is not allowed in this context.



            Dim rstFTPFiles As ADODB.Recordset
            Set rstFTPFiles = New ADODB.Recordset
            With rstFTPFiles
                Set .ActiveConnection = CurrentProject.Connection
                .Source = "FTPFiles"
                .CursorType = adOpenKeyset
                .LockType = adLockOptimistic
                .Open
            End With
       
            rstFTPFiles.Delete adAffectAllChapters    <--- Error occurs here
0
Comment
Question by:mmurphy1005
  • 4
6 Comments
 
LVL 12

Expert Comment

by:pique_tech
ID: 12087204
I think you want the adAffectAll argument rather than adAffectAllChapters
0
 

Author Comment

by:mmurphy1005
ID: 12087270
I tried it.  I got the...

Operation is not allowed in this context.

Error.

0
 
LVL 12

Expert Comment

by:pique_tech
ID: 12087352
Sorry, that's not quite right either.  Should have tested.

I think to approch this this way, you'll have to do some kind of loop and delete the records one at a time.  Alternately, you could create a connection object and then EXECUTE "DELETE * FROM FTPFiles" against that connection.

Dim cn as ADODB.Connection
Set cn = currentproject.connection
cn.Execute("DELETE * FROM FTPFiles")
Set cn = Nothing

I actually tested this and it works perfectly.  : )

0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 12

Accepted Solution

by:
pique_tech earned 250 total points
ID: 12087459
I think the recordset.delete method was designed to operate on a set of recordsets, the current record only, or a filtered recordset.  The Microsoft documentation (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmthrstdelete.asp) is, surprisingly, not much help.  ; )
0
 
LVL 6

Expert Comment

by:Plamodo
ID: 12112532
It wouldn't happen to be a query you are trying to delete records from, is it?  I know you mentioned 'table' in your initial question, but I thought I'd ask - since I've encountered error message #1 many times.
0
 
LVL 12

Expert Comment

by:pique_tech
ID: 12489964
mmrphy1005:  I'm curious what it was about my suggestions that warranted a C grade.  I'm not concerned about the points, I just want to be able to help others more effectively in the future.  Any feedback is appreciated.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question