Solved

Delete method raises error

Posted on 2004-09-17
6
757 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

623 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