Results 1 to 10 of 10
  1. #1
    kris9 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    May 2013
    Posts
    18

    Update table with autoID

    Hi,

    I have a table with following fields

    usrTable - ID(PK)(autonumber) , UsrID, Name, Date

    tempTable - UsrID, Date

    How can I create a update query to update data from tempTable to usrTable ? Fields to update are UsrID and Date.



    Not sure how to update with ID(auto number).

    Using Access 2010

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Why are you using tempTable?

    Is UsrID unique in both tables?

    Do you want to modify existing records in usrTable or do you want to add new records?
    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
    kris9 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    May 2013
    Posts
    18
    I am using the tempTable to bulk modify the Dates in usrTable.

    UsrID is unique in both tables. Only need to modify the Date in UsrTable is UsrID matches.


    Quote Originally Posted by June7 View Post
    Why are you using tempTable?

    Is UsrID unique in both tables?

    Do you want to modify existing records in usrTable or do you want to add new records?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Still not clear why a tempTable. How is data entered into tempTable? Why not just edit usrTable directly?

    The only common identifier field in both tables is usrID. These fields must be used to link the two tables. Cannot update usrID field. Can update Date field.

    Try:

    UPDATE tempTable INNER JOIN usrTable ON tempTable.UsrID = usrTable.UsrID SET usrTable.[Date]=tempTable.[Date];


    BTW, should not use reserved words as names. Date is a reserved word.
    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.

  5. #5
    kris9 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    May 2013
    Posts
    18
    thanks that works. Using the tempTable to all records to update then run the update query to update..


    How do I update only if value in the tempTable is not blank ? I have few more fields in the same table. sometime i only have to update one field.. so if other fields are blank, it overwrites the data to blank.



    Quote Originally Posted by June7 View Post
    Still not clear why a tempTable. How is data entered into tempTable? Why not just edit usrTable directly?

    The only common identifier field in both tables is usrID. These fields must be used to link the two tables. Cannot update usrID field. Can update Date field.

    Try:

    UPDATE tempTable INNER JOIN usrTable ON tempTable.UsrID = usrTable.UsrID SET usrTable.[Date]=tempTable.[Date];


    BTW, should not use reserved words as names. Date is a reserved word.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Try a WHERE clause:

    WHERE Not tempTable.[Date] Is Null
    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.

  7. #7
    kris9 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    May 2013
    Posts
    18
    I have three fields in tempTable - field1, field2, field3. these match to fields in usrTable. I need to update one of these fields from time to time.

    If I only have to update field2 and other fields are empty, it should not overwrite the related values in usrTable to empty.

    Tried the Not Is Null but on all the 3 fields criteria but not updating any field.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Post the sql statement you attempted. Or provide database for analysis. Follow instructions at bottom of my post.
    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.

  9. #9
    kris9 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    May 2013
    Posts
    18
    UPDATE tblTemp INNER JOIN tblUsers ON tblTemp.UsrID = tblUsers.UsrID SET tblUsers.BU = tblTemp.[BU], tblUsers.Location = tblTemp.[Location], tblUsers.Segment = tblTemp.[Segment], tblUsers.Dept = tblTemp.[Segment]
    WHERE ((Not (tblUsers.BU) Is Null) AND (Not (tblUsers.Location) Is Null) AND (Not (tblUsers.Segment) Is Null) AND (Not (tblUsers.Dept) Is Null));


    If I want to only update Location from tempTable and all the other fields are blank, its not updating location from above..

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Correct. It will only update records that meet all of the given criteria. Try:

    UPDATE tblTemp INNER JOIN tblUsers ON tblTemp.UsrID = tblUsers.UsrID SET tblUsers.BU = Nz(tblTemp.[BU], tblUsers.BU), tblUsers.Location = Nz(tblTemp.[Location], tblUsers.Location), tblUsers.Segment = Nz(tblTemp.[Segment], tblUsers.Segment), tblUsers.Dept = Nz(tblTemp.[Segment], tblUsers.Dept);
    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.

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

Similar Threads

  1. Replies: 7
    Last Post: 09-21-2012, 11:09 AM
  2. AutoID
    By hithere in forum Queries
    Replies: 8
    Last Post: 03-05-2012, 03:30 PM
  3. Replies: 1
    Last Post: 02-08-2012, 04:50 PM
  4. Replies: 1
    Last Post: 01-22-2011, 12:23 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