Results 1 to 8 of 8
  1. #1
    davem05 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    9

    Update Query Criteria - ensure source string is not zero length before update target

    I have an update query, where by some of the data from Excel may contain zero length strings. When I run the query it overwrites any data in my access tables with the zero length strings.
    I have tried various criteria in the query, but to no avail.

    The query, updates from the imported table to the correct location in the target table, the criteria I have used are along the lines of
    Like "*"
    Is Not Null --- I now understand Null is not zero length string, but that should still check there is a value there?



    I was thinking along the lines of the criteria checks there is some data in the source table before writing to the target table, is that right? Between the two above I fear I have something a bit more wrong than simply bad criteria?

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Can you post the SQL code of your Update query, along with the name of the field that is causing issues?

  3. #3
    davem05 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    9
    Quote Originally Posted by JoeM View Post
    Can you post the SQL code of your Update query, along with the name of the field that is causing issues?

    UPDATE ResultImport INNER JOIN [Test Details] ON ResultImport.labNumber = [Test Details].labNumber SET [Test Details].reqHypo = [ResultImport].[reqHypo], [Test Details].Test = [ResultImport].[resultHypo], [Test Details].dateProcessedHypo = [ResultImport].[dateProcessedHypo], [Test Details].qualityHypo = [ResultImport].[qualityHypo]
    WHERE ((([Test Details].resultHypo) Not Like "*")) OR ((([Test Details].dateProcessedHypo) Not Like "*")) OR ((([Test Details].qualityHypo) Not Like "*"));


    This is the query, it taks data from "ResultImport" to "Test Details", I am having trouble with "resultHypo", "dateProcessedHypo" and "qualityHypo", I have tried Like "*", Not Like"*", in case I was misunderstanding where I was aiming the reference.
    I want to update Test Details fields, from those in ResultImport, if there is data in the fields in ResultImport.
    Taking data from ResultImport to Test Details is no problem, it's just the zero length strings, I assume it is possible to be selective in the criteria about which data to transfer.

    Admittedly I haven't really looked at sql before, this will probably now change.

    Thanks a lot for looking through this.

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Since you are using OR conditions in your Criteria, if anyone of those fields is not blank, it will update all three. Which means, you could have two blank ones and it will still update.
    If you only want it to update if all three are not blank, replace all your "OR"s with "AND"s.

    Otherwise, if you want to handle each one separately, and only update the ones that are not blank, one way to do that is with three separate UPDATE queries, focusing on the one field at a time.

  5. #5
    davem05 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    9
    Okay, thanks for that, it was kind of what I was thinking I would have to do.

    Thanks for your time!

  6. #6
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Conceivably, you might be able to do it in one query using the NZ function to set it equal to itself if the other value is blank.
    Don't know if that would work, but it might be worth a try.

  7. #7
    davem05 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    9
    Thanks for looking at it, I ended up approaching it a little differently and have got the desired results.
    Thanks

  8. #8
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Out of curiosity, what did you end up doing?

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

Similar Threads

  1. update query with multiple criteria help
    By mbellas21 in forum Queries
    Replies: 2
    Last Post: 06-12-2013, 02:27 AM
  2. Query Update Criteria Continuous Form Row ID
    By andrebmsilva in forum Queries
    Replies: 2
    Last Post: 12-13-2012, 04:39 AM
  3. Replies: 4
    Last Post: 11-21-2012, 03:17 PM
  4. Replies: 1
    Last Post: 05-18-2012, 11:59 AM
  5. Query Criteria Lost After Table Update
    By matt4003 in forum Queries
    Replies: 10
    Last Post: 12-29-2009, 10:50 PM

Tags for this Thread

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