Results 1 to 7 of 7
  1. #1
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453

    delete specific number records

    Hi



    I have several tables containing 1000s of records.

    One field is named ChurchID_fk

    THis contains a list pf number 1-85 each one designating a specific church,

    I want to run a query where I can delete all records that are not equal to -say- 45. or put it another way I want to keep all records that are equal to 45

    I can delete all records that have a churchID_fk of greater that 45 and then run another query of those that have a churchid_fk of less than 45 but that seems clumsy and a waste of effort.

    I've looked but can't seem to get the expression correct to do this in one step.
    thanks

    Ian

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    WHERE ChurchID_fk<>45

  3. #3
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453
    Hi

    thanks for the reply - I was putting the figure in between the <>

    I now have

    Code:
    DELETE tbl_Baptism.ChurchID_fk, tbl_Baptism.FicheNo, tbl_Baptism.BirthDate, tbl_Baptism.DateOfBaptism, tbl_Baptism.YearOfBaptism, tbl_Baptism.FullDateOfBaptism, tbl_Baptism.ChildsName, tbl_Baptism.Surname, tbl_Baptism.Sex, tbl_Baptism.Parents, tbl_Baptism.Abode, tbl_Baptism.Occupation, tbl_Baptism.RefNo, tbl_Baptism.PageNo, tbl_Baptism.EntryNo, tbl_Baptism.Minister, tbl_Baptism.Notes, tbl_Baptism.ForenameSDX, tbl_Baptism.SurnameSDX, "ChurchID_fk"
    FROM tbl_Baptism
    WHERE ((("ChurchID_fk")<>45));

    But when I run it I get the error

    Data Mismatch in criteria expression.


    ChurchId_fk is formated number so I removed the "" ( as I thought these designated text)

    but running that clears the table.

    So I need help:-)

    thanks

    Ian

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Remove the quotes. ChurchID_fk is a field name on a table, select it and treat it the same as all the others.

  5. #5
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453
    Hi

    I tried loosing the quotes and it deleted all the records from the table

    I also tried

    Code:
    DELETE tbl_Baptism.ChurchID_fk, tbl_Baptism.FicheNo, tbl_Baptism.BirthDate, tbl_Baptism.DateOfBaptism, tbl_Baptism.YearOfBaptism, tbl_Baptism.FullDateOfBaptism, tbl_Baptism.ChildsName, tbl_Baptism.Surname, tbl_Baptism.Sex, tbl_Baptism.Parents, tbl_Baptism.Abode, tbl_Baptism.Occupation, tbl_Baptism.RefNo, tbl_Baptism.PageNo, tbl_Baptism.EntryNo, tbl_Baptism.Minister, tbl_Baptism.Notes, tbl_Baptism.ForenameSDX, tbl_Baptism.SurnameSDX
    FROM tbl_Baptism
    WHERE (((tbl_Baptism.ChurchID_fk)<>45));
    but that didn't work either

    thanks one and all Ian

  6. #6
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Hope you had a backup!

    The statement:
    DELETE * FROM tbl_Baptism WHERE ChurchID_FK<>45;
    should delete all records where the fk is not equal to 45.

    It doesn't make sense that your criteria is ignored, unless the data type is not a number.

  7. #7
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453
    Hi

    thanks, a compact operation plus your code worked

    cheers

    Ian

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 02-10-2017, 08:21 AM
  2. Delete specific records
    By Jen0dorf in forum Access
    Replies: 10
    Last Post: 07-20-2016, 01:52 PM
  3. Replies: 6
    Last Post: 11-27-2014, 03:21 AM
  4. Replies: 8
    Last Post: 02-09-2014, 07:25 PM
  5. Replies: 1
    Last Post: 01-24-2013, 05:50 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