Results 1 to 13 of 13
  1. #1
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162

    Query isnt updating table based on criteria

    Hi all - yep me again. Ive got an append query which isnt appending:
    Code:
    INSERT INTO ProjectsTable ( NAME, REFERENCE, NAME2 )
    SELECT ProjectsTable.NAME, ProjectsTable.REFERENCE, ProjectsTable.NAME2
    FROM ProjectsLinked LEFT JOIN ProjectsTable ON ProjectsLinked.NAME = ProjectsTable.NAME
    WHERE (((ProjectsTable.NAME) Is Null) AND ((ProjectsTable.REFERENCE)="!XXX01") AND ((ProjectsTable.NAME2)="Main Project")) OR (((ProjectsTable.REFERENCE)="!XXX99") AND ((ProjectsTable.NAME2)="Active Centre")) OR (((ProjectsTable.REFERENCE)="!XXX98"));
    Does this look like it should add fields which are Active centre or Main Project but not XXX99 / 98 or 01.



    There is one record in the table which its just not importing/appending??

    Am I correct in thinking this should update

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Try this ( try the SELECT part and see if it gives what you want before doing the Insert) [untested]



    INSERT INTO ProjectsTable ( NAME, REFERENCE, NAME2 )
    SELECT ProjectsTable.NAME
    , ProjectsTable.REFERENCE
    , ProjectsTable.NAME2
    FROM ProjectsLinked LEFT JOIN ProjectsTable
    ON ProjectsLinked.NAME = ProjectsTable.NAME
    WHERE
    (ProjectsTable.NAME Is Null) AND
    (ProjectsTable.NAME2 ="Main Project" OR ProjectsTable.NAME2="Active Centre")
    OR NOT
    (ProjectsTable.REFERENCE="XXX99"AND ProjectsTable.REFERENCE ="XXX98" AND ProjectsTable.REFERENCE ="XXX01") ;

  3. #3
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162
    I think its my not equal to which may be causing a problem? I thought <> or =!XXX was not equal to? If I run this in a query it displays nothing if I take away the <> or ! it displays the data I dont want to add - confused

  4. #4
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by shabbaranks View Post
    I think its my not equal to which may be causing a problem? I thought <> or =!XXX was not equal to? If I run this in a query it displays nothing if I take away the <> or ! it displays the data I dont want to add - confused

    From Help: [!charlist] Any single character not in charlist

    So the expression "!XXX01" would match anything *except* a value that contained an X, 0, or 1


    Also, "Name" is a reserved word that shouldn't be used as object names.
    In addition, it is not very descriptive. Name of what? A project, Supervisor, a car???

  5. #5
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162
    So what would be the best method if within my query I dont want to specifically add certain records to my table? As for name columns I created this before I knew there were reserved names I will amend that to be more specific.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Try this one
    INSERT INTO ProjectsTable ( NAME, REFERENCE, NAME2 )
    SELECT ProjectsTable.NAME
    , ProjectsTable.REFERENCE
    , ProjectsTable.NAME2
    FROM ProjectsLinked LEFT JOIN ProjectsTable
    ON ProjectsLinked.NAME = ProjectsTable.NAME
    WHERE
    (ProjectsTable.NAME Is Null) AND
    (ProjectsTable.NAME2 ="Main Project" OR ProjectsTable.NAME2="Active Centre")
    OR NOT
    (ProjectsTable.REFERENCE="XXX99" AND ProjectsTable.REFERENCE ="XXX98" AND ProjectsTable.REFERENCE ="XXX01") ;

  7. #7
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by shabbaranks View Post
    So what would be the best method if within my query I dont want to specifically add certain records to my table? As for name columns I created this before I knew there were reserved names I will amend that to be more specific.
    Did you try the example from Orange??
    Try the select portion first to ensure that all of the records are being selected, then add the INSERT part.

  8. #8
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162
    Hi,

    I tried what orange suggested and returned blanks. I have made slight progress I can avoid importing the columns I dont want by using Like but its still importing everything again when I run the query....

    Code:
    INSERT INTO ProjectsTable ( NAME, REFERENCE, NAME2 )
    SELECT ProjectsLinked.NAME, ProjectsLinked.REFERENCE, ProjectsLinked.NAME2
    FROM ProjectsLinked
    WHERE (((ProjectsLinked.REFERENCE) Not Like "XXX01" And (ProjectsLinked.REFERENCE) Not Like "XXX99" And (ProjectsLinked.REFERENCE) Not Like "XXX98") AND ((ProjectsLinked.NAME2) Like "Active Centre")) OR (((ProjectsLinked.NAME2) Like "Main Project"));

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Make an mdb version of your data base and post it so we can work with the copy.
    Remove anything private/confidential.

    Do a compact and repair and zip the mdb.

  10. #10
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162
    When you say mdb its accdb, hope this isnt a problem - thanks.

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Well I have Acc2003, and ssanfu indicates he has Acc2000. accdb is new in Acc2007. So we can not open/read/use an accdb.
    In Acc2007, you have an option(somewhere) to save a copy of your database in mdb format.

  12. #12
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162
    It wont let me convert to an older version of Access due to the features and settings of the database which I have used.

  13. #13
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by shabbaranks View Post
    It wont let me convert to an older version of Access due to the features and settings of the database which I have used.
    OK, then... back to basics.

    First, you should use brackets around "NAME", since it is a reserved word.

    Next, try this:

    Code:
    SELECT ProjectsTable.[NAME]
    , ProjectsTable.REFERENCE
    , ProjectsTable.NAME2
    FROM ProjectsLinked LEFT JOIN ProjectsTable 
    ON ProjectsLinked.[NAME] = ProjectsTable.[NAME];
    If that returns records, then add a WHERE condition:

    Code:
    SELECT ProjectsTable.[NAME]
    , ProjectsTable.REFERENCE
    , ProjectsTable.NAME2
    FROM ProjectsLinked LEFT JOIN ProjectsTable 
    ON ProjectsLinked.[NAME] = ProjectsTable.[NAME]
    WHERE
    (ProjectsTable.[NAME] Is Null);
    Again, if the correct records are returned, ass another WHERE condition:
    Code:
    SELECT ProjectsTable.[NAME]
    , ProjectsTable.REFERENCE
    , ProjectsTable.NAME2
    FROM ProjectsLinked LEFT JOIN ProjectsTable 
    ON ProjectsLinked.[NAME] = ProjectsTable.[NAME]
    WHERE
    (ProjectsTable.[NAME] Is Null) AND
    (ProjectsTable.NAME2 ="Main Project" OR ProjectsTable.NAME2="Active Centre");
    Then add the last condition:

    Code:
    SELECT ProjectsTable.[NAME]
    , ProjectsTable.REFERENCE
    , ProjectsTable.NAME2
    FROM ProjectsLinked LEFT JOIN ProjectsTable 
    ON ProjectsLinked.[NAME] = ProjectsTable.[NAME]
    WHERE
    (ProjectsTable.[NAME] Is Null) AND
    (ProjectsTable.NAME2 ="Main Project" OR ProjectsTable.NAME2="Active Centre") AND NOT
    (ProjectsTable.REFERENCE="XXX99" AND ProjectsTable.REFERENCE ="XXX98" AND ProjectsTable.REFERENCE ="XXX01") ;
    Not sure of the how you want the field exclusions order to be. But the thing is to get the select working first, then add the INSERT clause.

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

Similar Threads

  1. Replies: 3
    Last Post: 08-08-2011, 11:02 AM
  2. Replies: 2
    Last Post: 07-07-2011, 08:25 AM
  3. Replies: 7
    Last Post: 12-14-2010, 11:10 AM
  4. IIF Criteria based on another table
    By BED in forum Queries
    Replies: 6
    Last Post: 11-24-2010, 01:55 PM
  5. query - criteria based on another row field value
    By techexpressinc in forum Queries
    Replies: 1
    Last Post: 05-29-2009, 04:17 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