Hi i am trying to DELETE a Record if the details do not exist within a table. Here is my code below; - Dim strSQL As String
-
Dim strSQL2 As String
-
Dim Reply As String
-
Dim db As Database
-
Dim rst As Recordset
-
Dim SeqItemNo As Integer
-
-
DoCmd.SetWarnings False
-
-
Set db = CurrentDb()
-
Set rst = db.OpenRecordset("SELECT * FROM preordlin")
-
-
DoCmd.Save
-
DoCmd.GoToRecord , , acFirst
-
-
SeqItemNo = 1
-
-
Do
-
rst.Edit
-
Me.Requery
-
rst!StkID = DLookup("[StkID]", "stkmas", "[StkShortDesc] ='" & rst!StkShortDesc & "'")
- If IsNull(rst!StkID) Then
-
Reply = MsgBox("There are Stock Items present that do not belong to our existing Stock files. Would you like to DELETE them?", vbYesNo, "None Existent Stock Details!")
-
If Reply = vbYes Then
-
db.Execute "DELETE * FROM preordlin WHERE IsNull(StkID) And OrderNo = [Forms]![frmCustomerOrderForm]![sfrmSOHeader]![OrderNo]"
-
Else
-
Exit Sub
-
End If
-
Else
-
rst!Price = DLookup("[SalePrice1]", "primas", "[StkID] =" & rst!StkID)
-
rst!Cost = DLookup("[CostPrice1]", "primas", "[StkID] =" & rst!StkID)
-
rst!ItemNo = rst!ItemNo + SeqItemNo
-
rst.update
-
SeqItemNo = SeqItemNo + 1
-
End If
-
rst.MoveNext
-
Loop Until rst.EOF
-
rst.Close
-
Me.Requery
-
Set rst = Nothing
-
-
cmdCheckStock.Enabled = False
-
cmdUpdateInformation.Enabled = True
-
cmdAssignDetails.Enabled = False
-
cmdcalcgrainmeasures.Enabled = False
-
cmdImportintoOrderline.Enabled = False
-
-
DoCmd.SetWarnings True
I have tried many ways in which to DELETE particular records, all either failed or displayed a variety of messages such as Too Few Parameters, I am locked out by another user, Error due to StkID doesn't exist (Which i why i am wanting to delete the item). The only way i managed to delete these records is physically pressing the delete button on every record itself.
Could anyone tell me why this record will not delete? At present the code functions without errors and just moves on to the next record, but doesn't delete any in the process.
3 1902
I'm not an expert here, but assuming you've got the [forms]!.....![orderno] right, I had a similar problem with something like this a while ago, but a SELECT not a DELETE. - "DELETE * FROM preordlin WHERE IsNull(StkID) And OrderNo = [Forms]![frmCustomerOrderForm]![sfrmSOHeader]![OrderNo]"
might work if you change it to: - "DELETE * FROM preordlin WHERE IsNull(StkID) And OrderNo =" & [Forms]![frmCustomerOrderForm]![sfrmSOHeader]![OrderNo]
I'm not an expert here, but assuming you've got the [forms]!.....![orderno] right, I had a similar problem with something like this a while ago, but a SELECT not a DELETE. - "DELETE * FROM preordlin WHERE IsNull(StkID) And OrderNo = [Forms]![frmCustomerOrderForm]![sfrmSOHeader]![OrderNo]"
might work if you change it to: - "DELETE * FROM preordlin WHERE IsNull(StkID) And OrderNo =" & [Forms]![frmCustomerOrderForm]![sfrmSOHeader]![OrderNo]
Thanks for the info, unfortunately it still didn't work.
NeoPa 32,566
Recognized Expert Moderator MVP
I think line #13 is extraneous (not required). What is it there for? I can't see that it's doing anything.
Likewise line #20 shouldn't be there (after .Edit).
Other than that, I suspect the DELETE fails due to the record being locked by your VBA code. You won't see the warning message because they're disabled.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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: Susan Bricker |
last post by:
I have a command button on a form that is supposed to Delete the record
being displayed. The record is displayed one to a form. The form is
not a Pop-Up nor is it Modal. Tracing the btnDelete event routine shows
that AllowDeletions is TRUE.
When the Delete button is clicked (without TRACE ON), I get a 'beep',
the recordselector (vertical bar on left of form) gets dark in color,
but the record is not deleted. Also, there is no error...
|
by: Bob Bridges |
last post by:
Start with two tables, parent records in one and child records in the other,
a one-to-many relationship. Create a select statement joining the two.
Display the query in datasheet mode. When I delete a row, only the child
record is deleted from the source tables; the parent record is still
there...which is what I wanted.
Now display fields from that query in a continuous form. When I delete a
record from that form, one of the child...
|
by: Phil Stanton |
last post by:
Sorry to repost, but am having another look at deleting a record.
I have a form (Member) and have removed all the event procedures associated
with the Form (OnCurrent, OnDelete, OnActivate etc)
When I click on the record bar and press delete it comes up with the correct
message "You are about to delete 1 record ....", the record count drops by 1
and I say "Yes - delete it". Seems OK, record is no longer there.
Than after closing the form...
| |
by: Craggy |
last post by:
Hi,
I am trying to pop up a yes/no message box so that a user can delete a record in a continuous form. The default delete message is a bit sloppy because it seems to move the continuous form to the position of the record u want to delete. If you then choose to not to delete the record it looks to a user as if it has deleted every record before the one you chose not to delete.
To get around this I made a yes/no msgbox pop up and only after...
|
by: Markw |
last post by:
Hi folks I think I've got a variable problem but not 100% sure.
Background: I took the CMS example from chapter 6 in "Build your Own Database Driven Website Using PHP&MySQL" and have attempted to modify it for use in my own database. It almost works for me LOL.
contact.php returns my dive buddies first and last name and gives me the option to either Edit or Delete them. Currently the delete option is not active.
When I choose to edit...
|
by: beacon |
last post by:
Hi everybody,
This is probably going to sound unorthodox, but I have to log records that are deleted...I know, go figure.
Anyway, I have a form with a (continuous) subform, and on the subform I have a command button, called cmdDelete, that launches a dialog form, called frmDeleteCurrentRecord, where the user has to enter their name and a reason.
I have managed, through a ton of trial and tribulation, found a way to delete the current...
|
by: matthewslyman |
last post by:
I have an unusual design and some very unusual issues with my code... I have forced Access to cooperate on everything except one issue - record deletion.
My form design involves a recursively nested form. In other words, the form, m_settings_menueditor_recursive has a single subform; m_settings_menueditor_recursive (both are viewed as datasheets - so the form is its own subdatasheet.) The Form_Open event modifies the form's recordset so...
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |