Solved

Delete method raises error

Posted on 2004-09-17
6
756 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

734 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