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
16 3398
Kevin,
You have the delete and select in the wrong order....select comes before delete. -
For I = 1 To DeletedQty
-
DoCmd.RunCommand acCmdSelectRecord
-
DoCmd.RunCommand acCmdDeleteRecord
-
-
Next I
Thanks a lot! That fixed my problem. I love this forum.
The problem still exists but only when I'm deleting a large quantity like 200. Anything under 100 seems to work fine.
Any other ideas?
Kevin
I thought you were using this code to delete few records that were being selected by the user. If you are trying to do a bulk delete, create a delete query that places any constraints for the delete in the criteria row of the query grid. Then run the query using the DoCmd.OpenQuery method as needed. If you need more help on this, let me know.
I'm pretty new at this stuff, so I'm going to need more help. So right now my form has a list box that lists all of the records in my table. Once I select one record I delete the selected record and then the next record. This just continues until the number of records is deleted. My records are sorted by Item description so you can delete mutliple records of one item.
As for the query, would i just create a query that list the records by item number?
Can you give me an example of the code for the open query cmd?
Thanks,
Kevin
I'm pretty new at this stuff, so I'm going to need more help. So right now my form has a list box that lists all of the records in my table. Once I select one record I delete the selected record and then the next record. This just continues until the number of records is deleted. My records are sorted by Item description so you can delete mutliple records of one item.
As for the query, would i just create a query that list the records by item number?
Can you give me an example of the code for the open query cmd?
Thanks,
Kevin
You can execute a direct sql statement or save the sql as a query by pasting the sql (without the ending ;) to the sql view of a query and save as qryDelete.
Here is an example of executing an sql statement directly
. The syntax assumes you have a link named [ID] between the table and the form that is numeric....also , note that you don't need the where clause if you are deleting all the records from the table. -
DoCmd.RunSQL ("Delete * from [YourTable] where [YourTable].[ID] >= " & Me!ID & ";")
-
-
Me.Refresh
_______________ _______________ _______________ _
Here is example of executing a saved query via the openquery method: - DoCmd.OpenQuery "qryDelete", acNormal, acEdit
Thanks for your help,
I got the DCmd.OpenQuery to work. The only problem I have is that when I open the query the data sheet view opens and then does the delete. I'm able to close the form after it's done but this looks bad to the user because the datasheet opens over the form. Is there anyway to keep the datasheet view in the background so the user can't see it.
Thanks again,
Kevin
Thanks for your help,
I got the DCmd.OpenQuery to work. The only problem I have is that when I open the query the data sheet view opens and then does the delete. I'm able to close the form after it's done but this looks bad to the user because the datasheet opens over the form. Is there anyway to keep the datasheet view in the background so the user can't see it.
Thanks again,
Kevin
Kevin,
Yes, there is a way. Change your OpenQuery syntax to the following: - DoCmd.OpenQuery "yourQueryName"
You can also avoid getting any confirmations or prompts by doing the following: -
DoCmd.SetWarnings False
-
DoCmd.OpenQuery "YourQryName"
-
DoCmd.SetWarnings True
Hi,
I tried DoCmd.OpenQuery "qryAssetListBo x" and the query still shows up.
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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?
| |