Results 1 to 5 of 5
  1. #1
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,368

    Query Transferring Specific Postcodes And Shouldn't

    Hi Guy's, i have this simple query where i am trying to update tblRoutes From tblEdit within the shipment week

    So i am trying exclude 14 postcodes (if any exist in the specific week) therefore using simple method of



    In the criteria of Postcodes, i have got the following
    <> "Postcode1" Or <> "Postcode2" etc up to Postcode14

    When I run the code, if there are postcodes within that week that i am trying to exclude, they are pulling through and adding to tblRoutes

    I would have thought using the criteria that I have, it shouldn't pull them through ?

    Click image for larger version. 

Name:	Capture.JPG 
Views:	20 
Size:	43.6 KB 
ID:	49834

    Code:
    strSQL = "INSERT INTO tblRoutes ( DelTo, Town, PostCode ) " _
            & "SELECT qryCheckAdded.DelTo, qryCheckAdded.Town, qryCheckAdded.PostCode " _
            & "FROM qryCheckAdded;"
    
    
    Set rs = CurrentDb.OpenRecordset("Select * From tblRoutes WHERE Driver Is Null")
        
    Do Until rs.EOF
        
        With rs
        .Edit
        !DelDate = Format(Now(), "dd/mm/yyyy")
        .Update
        .MoveNext
        
        End With
        
    Loop
    
    
        DoCmd.SetWarnings False
            DoCmd.RunSQL strSQL
        DoCmd.SetWarnings True
            
        Forms!frmPlanning!frmPlanningDS.Requery

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    <> with OR does not work how you expect. Try AND.

    Or use NOT IN()

    NOT IN("postcode1", "postcode2", ...)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  4. #4
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    You shouldn't group by Postcode with criteria Is Null. Change that from Group By to Where.

    Possibly one or both of the other field with filter criteria should also be Where
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  5. #5
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,368
    Thank you guy's
    Changed to June7 approach
    NOT IN("postcode1", "postcode2", ...)
    Changed to Colin's suggestion from Group By to Where in the NULL field

    Works great
    Thank you

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

Similar Threads

  1. Update Query modifying records it shouldn't.
    By akeller in forum Queries
    Replies: 5
    Last Post: 12-12-2018, 12:30 PM
  2. query to find postcodes
    By marc aalders-dunthorne in forum Queries
    Replies: 11
    Last Post: 01-21-2015, 12:49 PM
  3. Replies: 1
    Last Post: 08-28-2013, 06:49 AM
  4. Validation for British postcodes
    By Helen269 in forum Database Design
    Replies: 7
    Last Post: 02-23-2012, 12:16 PM
  5. Replies: 0
    Last Post: 04-26-2008, 09:59 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