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
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)? - DoCmd.SetWarnings False
-
DoCmd.OpenQuery "YourQryName"
-
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. -
Application.Echo False
-
DoCmd.Hourglass True
-
DoCmd.OpenQuery "qryAssetListBox"
-
Application.Echo True
-
DoCmd.Hourglass False
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. -
-
-
Private Sub cmdMultiDeleteRecord_Click()
-
Dim DeletedQty As Integer
-
-
If Me.Dirty Then Me.Dirty = False
-
-
DoCmd.SetWarnings (WarningsOff)
-
-
If Not IsNull(Me.NumberDeleted) Then
-
DeletedQty = Me.NumberDeleted
-
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.OpenQuery "qryAssetListBox"
-
RunCommand acCmdSelectRecord
-
DoCmd.RunCommand acCmdDeleteRecord
-
-
Next I
-
-
Me.Requery
-
-
End If
-
-
MsgBox DeletedQty & " record(s) deleted!", vbOKOnly, "Record Deleted"
-
-
Exit_cmdMultiDeleteRecord_Click:
-
-
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
-
DoCmd.SetWarnings (WarningsOn)
-
-
NumberDeleted.Value = Null
-
-
-
End Sub
-
-
Thanks again,
Kevin
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).
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. -
Private Sub cmdMultiDeleteRecord_Click()
-
Dim DeletedQty As Integer
-
-
If Me.Dirty Then Me.Dirty = False
-
-
DoCmd.SetWarnings (WarningsOff)
-
-
If Not IsNull(Me.NumberDeleted) Then
-
DeletedQty = Me.NumberDeleted
-
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.RunCommand acCmdSelectRecord
-
DoCmd.RunCommand acCmdDeleteRecord
-
If I < DeletedQty Then
-
DoCmd.GoToRecord , , acNext
-
Else
-
Exit For
-
End If
-
Next I
-
-
MsgBox DeletedQty & " record(s) deleted!", vbOKOnly, "Record Deleted"
-
-
End If
-
-
Exit_cmdMultiDeleteRecord_Click:
-
Me.Refresh
-
DoCmd.SetWarnings (WarningsOn)
-
NumberDeleted.Value = Null
-
-
End Sub
-
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
It could be lines 8 thru 12 of the above code that is causing your problem.
Change this: - If Not IsNull(Me.NumberDeleted) Then
-
DeletedQty = Me.NumberDeleted
-
Else
-
DeletedQty = 1
-
End If
To this: - If nz(Me.NumberDeleted,0) > 1 Then
-
DeletedQty = Me.NumberDeleted
-
ElseIf nz(Me.NumberDeleted,0) = 1 Then
-
DeletedQty = 1
-
Else
-
DeletedQty = 0 'no records to delete
-
Exit Sub
-
End If
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 ,
|
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...
|
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
|
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).
|
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,...
| |
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
|
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...
|
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
|
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...
|
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...
|
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,...
| |
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |