Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    fabiobarreto10 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2011
    Posts
    169

    delete records when you change a field

    Gentlemen,




    I have a subform with a field step with the list box, three data fields and one text field.

    how do I change a field in the listbox, delete all records of this record and all records below.

    Thank you.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    The lack of replies would indicate that nobody understands the problem. Can you clarify, perhaps with an example of what the data looks like?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    fabiobarreto10 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2011
    Posts
    169
    okay. I'm sending some pictures. see that the image I change the value 2, and 3 in the image the result I'm ten-
    ing.

    Thank you.Click image for larger version. 

Name:	picture1.jpg 
Views:	4 
Size:	113.4 KB 
ID:	6993Click image for larger version. 

Name:	picture2.jpg 
Views:	5 
Size:	113.9 KB 
ID:	6994Click image for larger version. 

Name:	picture3.jpg 
Views:	4 
Size:	97.9 KB 
ID:	6995

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    In general:

    CurrentDb.Execute "DELETE * FROM TableName WHERE..."

    The WHERE clause would have to identify the records to be deleted. If I'm seeing right, you'd want to match the CodProduto field and have > on the CodPassosStat field. Or perhaps the Data Programada field.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    fabiobarreto10 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2011
    Posts
    169
    pbaldy, Thanks for helping.

    My problem is in WHERE. By changing the field, I need to delete all "below" the changed record.
    And also delete two values ​​of two fields of the record being changed.

    In the where clause I need to specify this, but I'm not getting.

    Thank you.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    How do you define "below", in terms of the data? I offered two thoughts, which you haven't addressed.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    fabiobarreto10 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2011
    Posts
    169
    "below" are all records after the
    changed record. (Picture3).


    Sorry, this is because it became clear to me.


    is a CodProduto for many steps (CodPassosStatus).
    I need to specify only those records that are
    further, beyond the field and DataProgramada
    PontoFocal the record being changed.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    So something along the lines of

    CurrentDb.Execute "DELETE * FROM TableName WHERE CodProduto = " & Me.CodProduto & " And DataProgramada > #" & Format(Me.DataProgramada, "mm/dd/yy") & "#", dbFailOnError

    and then requery the subform.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    fabiobarreto10 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2011
    Posts
    169
    Thanks for helping.


    Simply put the line of code you sent me
    the event by changing the field. Step. (I modified the name of
    table and the format to dd / mm / yyyy).


    Excludes records as I wanted, just kept on each
    Deleted the word field, and did not exclude the field and DAtaProgramada PontoFocal


    the record was changed


    (picture becomes clearer)
    Thank you.
    Thank you.Click image for larger version. 

Name:	novaImagem1.jpg 
Views:	4 
Size:	98.5 KB 
ID:	7001Click image for larger version. 

Name:	nova imagem2.jpg 
Views:	3 
Size:	101.6 KB 
ID:	7002

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    It does not appear you requeried the subform, which will get rid of the deleted records.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    fabiobarreto10 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2011
    Posts
    169
    Yes, sorry I forgot.


    I used this:


    Form_fFiltros.combProduto_AfterUpdate
    but sometimes get an error.


    How do I update only the subform?






    I just have a problem, when the field of DataReprogramada steps
    previous changes, and generated an auditor in another table.
    With the SQL statement that does not work.
    I do not understand why the records that will probably be deleted, never
    will have the field DataReprogramada Filled.
    Only the records prior to the record being changed.


    I took referential integrity and work, but would like to maintain the integrity
    reference.


    Sometimes it is not excluded (images) see the third record in the Step field, I change the value but does not delete.


    I need to delete the registry regardless of whether the date is higher or lower than today.

    .Click image for larger version. 

Name:	newpicture1.jpg 
Views:	2 
Size:	98.0 KB 
ID:	7003Click image for larger version. 

Name:	newpicture2.jpg 
Views:	3 
Size:	99.4 KB 
ID:	7004

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Since your code is in the subform:

    Me.Requery

    As to what records are deleted, you need to specify in data terms, not visual terms, which records should be deleted. You can see I used date, but if that's not appropriate, what is?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    fabiobarreto10 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2011
    Posts
    169
    Thanks for helping me.
    Simply, I can not understand why time is not cleaning.
    I can send the db?

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    You should be able to attach it here, after a compact/repair and zipping it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  15. #15
    fabiobarreto10 is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2011
    Posts
    169
    sorry, this new version of the site's forum, I do not know where I choose to upload files.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 01-24-2012, 02:16 PM
  2. How to delete the duplicated records in a field?
    By jamal numan in forum Access
    Replies: 7
    Last Post: 10-28-2011, 01:39 PM
  3. Replies: 1
    Last Post: 07-14-2011, 05:44 AM
  4. Delete all records
    By stryder09 in forum Access
    Replies: 6
    Last Post: 05-11-2011, 02:07 PM
  5. Delete all records in a field
    By cotri in forum Forms
    Replies: 6
    Last Post: 01-29-2010, 02:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums