Results 1 to 12 of 12
  1. #1
    gaker10 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    262

    Delete Query based on records in a linked Excel table

    I have an Add and Update Query for this. Now I need a delete query.



    I need my delete query to delete entire records based on matching between a Field1 in my linked excel table, and a Field11 in my database. Don't know why I can't seem to find this anywhere that does not involve the use of VBA.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Use the query wizard and make the FIND DUPLICATES IN TABLE query.
    Look at the design (as an example),
    Using your example, You want to delete records in the Field1 so you must use a 'sub-query' using the IN statement in the field criteria.

    Do the same for DELETE query.
    delete * from table, where [field1] (in select [field1] from table2)

  3. #3
    gaker10 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    262
    Is that a criteria expression or a VBA expression? "delete * from table, where [field1] (in select [field1] from table2)"

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Youll understand it from the FIND DUPLICATES query.
    Query only...NO vba needed.

  5. #5
    gaker10 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    262
    I don't see the connection between the DUPS query and the delete query, other than finding matches.

  6. #6
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    The IN STATEMENT in the sql inside the field you want to match.
    A query in a query.

    (tho yours will be a DELETE not select)
    The IN qry will be the list of items you want to remove
    The DEL qry delete them.

  7. #7
    gaker10 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    262
    I'm not even sure how to set up the query before the criteria part though. Is this right so far?

    Click image for larger version. 

Name:	queries3.png 
Views:	10 
Size:	7.3 KB 
ID:	18247

  8. #8
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Thats a start, (you need 2 queries)
    now you need to filter the records you get the list of what to delete. (in criteria)
    save this query as qsRecs2Del

    Then start a new query on the table you want to delete
    pull down the field you want to MATCH to the query above that has the list to delete.
    in the critieria , type: IN (select [field] from qsRecs2Del)
    call this qry qdDelRecs


    Its EXACLTY like the 'find dupes' example, but instead of find, change it to a delete qry.

  9. #9
    gaker10 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    262
    Oh I see now, just from your statements. The "from" table is actually the result of a matching query, and so I was looking for a reference to a table, not a query, hehe.

  10. #10
    gaker10 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    262
    I did what you suggested and I get the message: Specify the table containing the records you want to delete. Here's my query criteria:

    Click image for larger version. 

Name:	queries4.png 
Views:	8 
Size:	7.7 KB 
ID:	18255

  11. #11
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Is there a query called "Filter"? (see your IN statement)
    It needs to be a table or query

    Best practice is to name all tables start w T
    reports w R
    etc.

    all queries starting with Q

    qs.. select query
    qu.. update
    qa.. append
    qm.. make table
    qx.. cross tab
    qd.. delete
    qn.. union query
    Last edited by ranman256; 09-30-2014 at 08:50 AM.

  12. #12
    gaker10 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    262
    Click image for larger version. 

Name:	queries5.png 
Views:	7 
Size:	112.5 KB 
ID:	18261That's the matching query:

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

Similar Threads

  1. Replies: 1
    Last Post: 04-23-2012, 10:40 AM
  2. Replies: 2
    Last Post: 01-24-2012, 02:16 PM
  3. Replies: 3
    Last Post: 05-03-2011, 01:36 PM
  4. Linked table Query based form
    By sesproul in forum Forms
    Replies: 1
    Last Post: 01-21-2010, 08:46 PM
  5. Replies: 2
    Last Post: 10-27-2009, 07:09 AM

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