473,387 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Unable to DELETE a RECORD from a FORM

129 100+
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 1887
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 100+
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,556 Expert Mod 16PB
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
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: ...
3
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...
4
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...
5
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...
4
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)...
4
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...
1
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...
10
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...
31
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...

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.