473,320 Members | 1,896 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,320 software developers and data experts.

delete records using search form

mseo
181 100+
hi,
I have a form for deleting records but I use unbound controls in the mainform to set the criteria of filtering the records that will be viewed in the subform
I have delete command button in the mainform
I just need when i set the criteria for viewing the details after click Find then click delete, the data in the subform to be deleted
I don't like to use cascade delete in the subforms because the record will filled with (deleted) and in the case the form will not be user friendly
thanks in advance for any help you may provide me with
May 15 '10 #1
13 3226
NeoPa
32,556 Expert Mod 16PB
Firstly, let's look at the design of a search form using unbound controls. Example Filtering on a Form should cover that for you.

Next, a command button to delete the record. This can be done on a set of records or the currently selected one alone. A filtered list would most easily be done with a delete query using the same filter. An individual record could also be done with a delete query, filtering on the ID of the record, but equally could be done using :
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunCommand acCmdDeleteRecord
This deletes the currently selected record only.

Last, if you ever get a situation where you have record placeholders for deleted records you should think of issuing a .Requery call for the form it's on. This will reload all records for you.
May 16 '10 #2
mseo
181 100+
@NeoPa
hi,
I need to know about how to delete filtered records using sql statement within vba code
thank you very much
Jul 1 '10 #3
NeoPa
32,556 Expert Mod 16PB
Assuming then, that you have your subform already filtered, you would need to execute some SQL similar to the following :
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.RunSQL("DELETE FROM [YourTable] WHERE " & _
  2.                   Me.YourSubformControl!Filter)
  3. Call Me.YourSubformControl!Requery
Don't forget the call to .Requery afterwards though. Without this you'll see those messy #Deleted entries.
Jul 2 '10 #4
mseo
181 100+
@NeoPa
thank you
ok, I have tbl_production and child table tbl_productiondetail
the filtered records from the child table
when I executed the code you provided me
Expand|Select|Wrap|Line Numbers
  1. Private Sub delete_Click()
  2. Call DoCmd.RunSQL("DELETE FROM [tbl_productiondetail] WHERE " & _
  3.                   Me.MultiCriteria_subform!Batch_No)
  4. Call Me.MultiCriteria_subform.Requery
  5. End Sub
that delete all the records in the child table not the filtered records only
Jul 4 '10 #5
NeoPa
32,556 Expert Mod 16PB
Your line #3 is quite different from what I suggested. You need to use the .Filter property, as this has already been set, and is already working (presumably), filtering the data exactly as you need it.

From what you've now posted I would guess the code should be :
Expand|Select|Wrap|Line Numbers
  1. Private Sub delete_Click()
  2.     Call DoCmd.RunSQL("DELETE FROM [tbl_productiondetail] WHERE " & _
  3.                       Me.MultiCriteria_subform!Filter)
  4.     Call Me.MultiCriteria_subform.Requery
  5. End Sub
As a final consideration, it occurs to me that you may also need to duplicate the effect of linking the main and the subform. That is to say the subform may already have an effective filter of having to match the data in the main form. If that is the case (and it usually is) then this would also need to be handled. What do you have set in the .LinkChildFields property of your subform ([MultiCriteria_subform]) and what is/are the control(s) on the main form that this/these relate to?
Jul 5 '10 #6
mseo
181 100+
hi,
I attached a form that has the same problem, so the name of the controls will be different from the previous mentioned in the code
I get error because of
Expand|Select|Wrap|Line Numbers
  1.  Me.Production_By_Product__subform!Filter) 
Run-time error '2455':
you entered an expression that has an invaild reference to the property form/report

thank you very much
Jul 8 '10 #7
mseo
181 100+
hi,
I really need any solution for this
please give my any suggestions
Jul 9 '10 #8
NeoPa
32,556 Expert Mod 16PB
I can't even look at attachments at work.

Generally, we work within the forum to posted information. Clearly, being from Egypt it is likely you will struggle with English, and I understand that, but generally we expect the question expressed clearly for us (in text on the page).

Just to be crystal clear, I'm happy to make special allowances in your case MSEO, but nevertheless I will have to wait until at least I get home to look at your attachment as I don't download from here onto my work PC.
Jul 9 '10 #9
mseo
181 100+
@NeoPa
thank you very much for your dedication
when I ask an expert like you, it's not about the english, it's all about the selection of terms that I have to use when I inquire about any dilemma, so I am sorry for the poor explanation of the problem
thank you again and over again
Jul 9 '10 #10
NeoPa
32,556 Expert Mod 16PB
I understand, and though I point it out to explain why I cannot help just now, I don't do so as a criticism. My best second language is French, and I would not manage as well in French as you do in English.

I will try to get on later from home to look at this again.
Jul 9 '10 #11
NeoPa
32,556 Expert Mod 16PB
There appears to be a lot of complicated stuff in here MSEO, but I'm afraid most of it seems unnecessary to me.

Something like this can be done with a single form. The search facilities in the header and the data in the detail. The footer can be used for Delete or Exit buttons or whatever.

I suggest you look again at the link I posted earlier (post #2) as that covers most of what you need. The SQL is pretty straightforward and similar to that posted in #4.

I suggest you look at getting the fundamental workings sorted before you add hiding things to your code. That just makes testing it more difficult and complicated. It's not a bad idea by any means, but best to add after the basics are working properly, then it doesn't get in the way.

I'm afraid this does mean taking a few steps backwards before going forward, but subforms were never really designed to be used for this. It's just overcomplicating a relatively straightforward issue.
Jul 9 '10 #12
mseo
181 100+
@NeoPa
thank you very much Neopa for your dedication
I am trying to restructure this sort of Forms
and I will follow your suggestions and comments about that form, because I really appreciate your approaches about this
thank you very much
Jul 10 '10 #13
NeoPa
32,556 Expert Mod 16PB
No worries.

I hope it turns out to be simpler for you in the long run. I expect it will :)
Jul 10 '10 #14

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

Similar topics

1
by: David Kevorsky | last post by:
Hello, On one of the forms of an in-house Access application (developer unavailable), user input is notaccepted on the textbox controls of the form. Note that none of the suggestions in the...
5
by: hpi | last post by:
Hello, I have a table : Batch It contains fields batchnummer : Number (Long Integer) datum : Date/Time status : Number (Long Integer) nr_records : Number (Long Integer)
6
by: Paul T. Rong | last post by:
Dear all, Here is my problem: There is a table "products" in my access database, since some of the products are out of date and stopped manufacture, I would like to delete those PRODUCTS from...
2
by: Robin | last post by:
I have a main table that I need to delete records that arn't referenced in another. Query says I cannot delete. If I remove the reference query all deletes ok. Hope there is a way around this ?...
4
by: felicia | last post by:
Hi All, Below is my code to delete records: adodcAllEntries.Recordset.MoveFirst Do While (adodcAllEntries.Recordset.EOF = False) If adodcAllEntries.Recordset.Fields(0) = selected_id Then...
7
by: flashguy | last post by:
Hi, Looking online for this related topic that will be exclusively used for MS ACCESS (2000 preferably) is extremely limited. Is it possible to add Multiple records with one click of a buttton...
10
by: mfaisalwarraich | last post by:
Hi Everybody. I wana look for some records which matches my search criteria. Dim rsMainTable As Recordset Const strDBPath = "C:\ExternalDatabase.mdb" Dim sql as String ...
15
by: busterbaxter | last post by:
I have an existing inventory database that I'm trying to make changes to. The database only has 1 table with the following fields: PartNumber ItemDescription Category Location Owner...
13
by: ramprakashjava | last post by:
hi, i hav "java.lang.NullPointerException" error while Deleting table records using checkbox in jsp here i enclosed files help quickly plzzz.. ...
8
by: munkee | last post by:
Hi everyone, I am using the following code adapted from Allen Browne: 'Purpose: This module illustrates how to create a search form, _ where the user can enter as many or few...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.