473,612 Members | 2,331 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unable to DELETE a RECORD from a FORM

129 New Member
Hi i am trying to DELETE a Record if the details do not exist within a table. Here is my code below;

Expand|Select|Wrap|Line Numbers
  1.     Dim strSQL As String
  2.     Dim strSQL2 As String
  3.     Dim Reply As String
  4.     Dim db As Database
  5.     Dim rst As Recordset
  6.     Dim SeqItemNo As Integer
  7.  
  8.     DoCmd.SetWarnings False
  9.  
  10.     Set db = CurrentDb()
  11.     Set rst = db.OpenRecordset("SELECT * FROM preordlin")
  12.  
  13.     DoCmd.Save
  14.     DoCmd.GoToRecord , , acFirst
  15.  
  16.     SeqItemNo = 1
  17.  
  18.     Do
  19.         rst.Edit
  20.         Me.Requery
  21.         rst!StkID = DLookup("[StkID]", "stkmas", "[StkShortDesc] ='" & rst!StkShortDesc & "'")
  22.         If IsNull(rst!StkID) Then
  23.             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!")
  24.             If Reply = vbYes Then
  25.                 db.Execute "DELETE * FROM preordlin WHERE IsNull(StkID) And OrderNo = [Forms]![frmCustomerOrderForm]![sfrmSOHeader]![OrderNo]"
  26.             Else
  27.                 Exit Sub
  28.             End If
  29.         Else
  30.         rst!Price = DLookup("[SalePrice1]", "primas", "[StkID] =" & rst!StkID)
  31.         rst!Cost = DLookup("[CostPrice1]", "primas", "[StkID] =" & rst!StkID)
  32.         rst!ItemNo = rst!ItemNo + SeqItemNo
  33.         rst.update
  34.         SeqItemNo = SeqItemNo + 1
  35.         End If
  36.         rst.MoveNext
  37.     Loop Until rst.EOF
  38.     rst.Close
  39.     Me.Requery
  40.     Set rst = Nothing
  41.  
  42.     cmdCheckStock.Enabled = False
  43.     cmdUpdateInformation.Enabled = True
  44.     cmdAssignDetails.Enabled = False
  45.     cmdcalcgrainmeasures.Enabled = False
  46.     cmdImportintoOrderline.Enabled = False
  47.  
  48.     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.
Sep 16 '08 #1
3 1902
mandanarchi
90 New Member
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.

Expand|Select|Wrap|Line Numbers
  1. "DELETE * FROM preordlin WHERE IsNull(StkID) And OrderNo = [Forms]![frmCustomerOrderForm]![sfrmSOHeader]![OrderNo]"
might work if you change it to:

Expand|Select|Wrap|Line Numbers
  1. "DELETE * FROM preordlin WHERE IsNull(StkID) And OrderNo =" & [Forms]![frmCustomerOrderForm]![sfrmSOHeader]![OrderNo]
Sep 16 '08 #2
Constantine AI
129 New Member
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.

Expand|Select|Wrap|Line Numbers
  1. "DELETE * FROM preordlin WHERE IsNull(StkID) And OrderNo = [Forms]![frmCustomerOrderForm]![sfrmSOHeader]![OrderNo]"
might work if you change it to:

Expand|Select|Wrap|Line Numbers
  1. "DELETE * FROM preordlin WHERE IsNull(StkID) And OrderNo =" & [Forms]![frmCustomerOrderForm]![sfrmSOHeader]![OrderNo]
Thanks for the info, unfortunately it still didn't work.
Sep 16 '08 #3
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.
Sep 16 '08 #4

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

Similar topics

8
4045
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
3961
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).
4
7839
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...
5
4134
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...
4
4394
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...
4
2566
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...
1
2408
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...
10
7153
beacon
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...
31
6655
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...
0
8173
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
8115
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,...
0
8617
Oralloy
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...
0
8568
jinu1996
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...
1
8254
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
8422
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...
1
6082
isladogs
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...
0
4111
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1416
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.