473,769 Members | 3,867 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delete Command has error when deleting multiple records.

24 New Member
Hi All,

I got a multiple delete working here but for some reason I occassionally get this error. The way the delete works is there is a text box where the user enters the quantity to delete. If it is blank it will delete 1 item. It never fails when I delete just 1 item but if I delete more than one item it fails but only some times. Here is the error:

"Run-time error '2046':

The command or action 'DeleteRecord' isn't available now."

Here is my code:

Private Sub cmdMultiDeleteR ecord_Click()
Dim DeletedQty As Integer

If Me.Dirty Then Me.Dirty = False

DoCmd.SetWarnin gs (WarningsOff)

If Not IsNull(Me.Numbe rDeleted) Then
DeletedQty = Me.NumberDelete d
Else
DeletedQty = 1
End If

If MsgBox("Are you sure you want to delete " & DeletedQty & " record(s)?", vbQuestion + vbYesNo, "Confirm Delete?") = vbYes Then

For I = 1 To DeletedQty
DoCmd.RunComman d acCmdDeleteReco rd *** Error Occurs Here ****
RunCommand acCmdSelectReco rd

Next I

MsgBox DeletedQty & " record(s) deleted!", vbOKOnly, "Record Deleted"

End If

Exit_cmdMultiDe leteRecord_Clic k:

DoCmd.DoMenuIte m acFormBar, acRecordsMenu, 5, , acMenuVer70
DoCmd.SetWarnin gs (WarningsOn)

NumberDeleted.V alue = Null

End Sub


Can somebody help me out and find out why it's not working?

Thanks,

Kevin
Oct 31 '08
16 3401
puppydogbuddy
1,923 Recognized Expert Top Contributor
Hi,

I tried DoCmd.OpenQuery "qryAssetListBo x" and the query still shows up.

Kevin
Hi Kevin,
That should have worked.

Did you try the code I gave you that includes the setWarnings (below)?
Expand|Select|Wrap|Line Numbers
  1. DoCmd.SetWarnings False
  2. DoCmd.OpenQuery "YourQryName"
  3. DoCmd.SetWarnings True
If the above syntax does not work, then use this syntax. The thing that bothers me is that I can't understand why the above syntax did not work. There must be something else going on in your code that is effecting this.
Expand|Select|Wrap|Line Numbers
  1.     Application.Echo False
  2.     DoCmd.Hourglass True
  3.     DoCmd.OpenQuery "qryAssetListBox"
  4.     Application.Echo True
  5.     DoCmd.Hourglass False
Nov 5 '08 #11
busterbaxter
24 New Member
I tried all of the solutions and the qry still pops up over the form. Here is my code for the delete. I'm using access 2007, not sure if that has anything to do with it.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. Private Sub cmdMultiDeleteRecord_Click()
  4. Dim DeletedQty As Integer
  5.  
  6. If Me.Dirty Then Me.Dirty = False
  7.  
  8. DoCmd.SetWarnings (WarningsOff)
  9.  
  10. If Not IsNull(Me.NumberDeleted) Then
  11. DeletedQty = Me.NumberDeleted
  12. Else
  13. DeletedQty = 1
  14. End If
  15.  
  16. If MsgBox("Are you sure you want to delete " & DeletedQty & " record(s)?", vbQuestion + vbYesNo, "Confirm Delete?") = vbYes Then
  17.  
  18. For I = 1 To DeletedQty
  19.  
  20.       DoCmd.OpenQuery "qryAssetListBox"
  21.       RunCommand acCmdSelectRecord
  22.       DoCmd.RunCommand acCmdDeleteRecord
  23.  
  24. Next I
  25.  
  26. Me.Requery
  27.  
  28. End If
  29.  
  30. MsgBox DeletedQty & " record(s) deleted!", vbOKOnly, "Record Deleted"
  31.  
  32. Exit_cmdMultiDeleteRecord_Click:
  33.  
  34. DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
  35. DoCmd.SetWarnings (WarningsOn)
  36.  
  37. NumberDeleted.Value = Null
  38.  
  39.  
  40. End Sub
  41.  
  42.  
Thanks again,

Kevin
Nov 5 '08 #12
puppydogbuddy
1,923 Recognized Expert Top Contributor
Kevin,
Boy are you confused. Not only did you mix code I gave you for a"bulk" delete, you did a select query instead of a delete query. I will get back to you with revised code as soon as I can (by tomorrow at the latest).
Nov 6 '08 #13
puppydogbuddy
1,923 Recognized Expert Top Contributor
Kevin,
After looking at your original code, I don't see how it ever worked for more than one record because you left out the "DoCmd.GoToReco rd , , acNext" as shown in the revised code below. Try the code below. If it works the way you want, then you won't need the bulk delete query that I mentioned previously. Let me know if this code does what you intended.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdMultiDeleteRecord_Click()
  2. Dim DeletedQty As Integer
  3.  
  4. If Me.Dirty Then Me.Dirty = False
  5.  
  6. DoCmd.SetWarnings (WarningsOff)
  7.  
  8. If Not IsNull(Me.NumberDeleted) Then
  9.        DeletedQty = Me.NumberDeleted
  10. Else
  11.         DeletedQty = 1
  12. End If
  13.  
  14. If MsgBox("Are you sure you want to delete " & DeletedQty & " record(s)?", vbQuestion + vbYesNo, "Confirm Delete?") = vbYes Then
  15.  
  16.       For I = 1 To DeletedQty
  17.            DoCmd.RunCommand acCmdSelectRecord 
  18.            DoCmd.RunCommand acCmdDeleteRecord  
  19.            If I < DeletedQty Then
  20.                DoCmd.GoToRecord , , acNext
  21.            Else
  22.                Exit For
  23.            End If
  24.      Next I
  25.  
  26.      MsgBox DeletedQty & " record(s) deleted!", vbOKOnly, "Record Deleted"
  27.  
  28. End If
  29.  
  30. Exit_cmdMultiDeleteRecord_Click:
  31.       Me.Refresh
  32.       DoCmd.SetWarnings (WarningsOn)
  33.       NumberDeleted.Value = Null
  34.  
  35. End Sub
  36.  
Nov 7 '08 #14
busterbaxter
24 New Member
Thanks for the code,

I still get the same error , The command or action 'DeleteRecord' isn't available.

I did use my old code with the open query and added your solution to not show the query and it seemed to work.

I do like the way your code works though. You can actually see the item being deleted from the form.

Is there any other reason I would be getting this Run-time error '2046' The command or action 'DeleteRecord' isn't available now.

Thanks for all of your help. I really appreciate it.

Kevin
Nov 7 '08 #15
puppydogbuddy
1,923 Recognized Expert Top Contributor
It could be lines 8 thru 12 of the above code that is causing your problem.

Change this:
Expand|Select|Wrap|Line Numbers
  1. If Not IsNull(Me.NumberDeleted) Then 
  2.        DeletedQty = Me.NumberDeleted 
  3. Else 
  4.         DeletedQty = 1 
  5. End If 
To this:
Expand|Select|Wrap|Line Numbers
  1. If nz(Me.NumberDeleted,0) > 1 Then 
  2.        DeletedQty = Me.NumberDeleted 
  3. ElseIf nz(Me.NumberDeleted,0) = 1 Then  
  4.         DeletedQty = 1 
  5. Else
  6.         DeletedQty = 0             'no records to delete
  7.         Exit Sub
  8. End If 
Nov 7 '08 #16
busterbaxter
24 New Member
Thanks puppydogbuddy,

For some reason, I do not receive the errors anymore. I've been testing it a lot today. I'll make the changes if I run into the error again. Thanks again for all of your help. You were so patient with me and gave me a bunch of solutions. Thanks for your time.

Kevin
Nov 7 '08 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2872
by: sql-db2-dba | last post by:
There are 2 tables A and B with A being the parent of B. Table A ( Col1 varchar(5) Not Null ) Table B ( B_PK varchar(5) Not Null ,
9
10666
by: Robert Schneider | last post by:
Hi to all, I don't understand that: I try to delete a record via JDBC. But I always get the error SQL7008 with the error code 3. It seems that this has something to do with journaling, since the table from which I want to delete has two foreign keys that references two other tables and it is also referenced by another table. But this shouldn't be a problem, since I set the commit mode to none (or *none) at all places where this makes...
8
4066
by: Steve | last post by:
I have several pairs of synchronized subforms in an application. I have a Delete button for each pair that uses the following code or similar to delete a record in the second subform: DoCmd.SetWarnings False DoCmd.RunCommand acCmdDeleteRecord DoCmd.SetWarnings True End If ExitHere: Me!SubName.SetFocus
3
3974
by: Uwe Range | last post by:
Hi to all, I am displaying a list of records in a subform which is embedded in a popup main form (in order to ensure that users close the form when leaving it). It seems to be impossible to delete a record in this subform. When I switched modal off and tried to delete a record from the list, I deleted a record on another form (below the popup form).
3
3904
by: Tim Marshall | last post by:
HI all, Access 2003, Jet back end. Rather than annoy my users in a particular app by having relationships with enforced relational integrity refuse to delete a record with related records, I'm using cascade delete. When I use a continuous form and a record is deleted, Access provides a warning that there are related records, do you want to continue (an aside - anyone know how to trap that warning on the form on error event?). However,...
6
2025
by: Mark Kurten | last post by:
for some reason when i delete a row, the row doesn't get deleted from the acutal data table in SQL server. my code follows what am i missing? thanks. Dim row As DataRow Try
5
9937
by: Neil | last post by:
I am getting time-out errors when I try to perform a simple delete on a linked server. The command is: Delete From MyTable Where PKID=12345 I have tried executing this command directly from Query Analyzer, but it just times out. However, when I run it from QA against the server itself (rather than from my local server against a linked server), it executes immediately. Similarly, if I run the same SQL command through an ODBC linked...
3
3812
by: Kevin M | last post by:
I have one table and have created a form from that table. Also, I have created a delete query. I want to but a button on the form which will delete all records from the table; however, I cannot get anything to work. I know this is probably simple for more experienced Access users. Any help would be greatly appreciated. Thanks Kevin
6
4089
by: scott.tang | last post by:
I'm experiencing a very strange problem. My application is MS Access front-end and MS SQL server back-end database. I have a SQL statement that deletes records from a table after an export process. The problem is occasionally when the delete statement is executed, these records no longer display on List Box (not even in the MS Access link table). But when close and reopen the form, those records reappear. It almost like MS SQL server...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.