Results 1 to 11 of 11
  1. #1
    Access_Blaster is offline User
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2010
    Posts
    339

    Update query help

    Hello,



    I want to use a local temp table to update a SQL table, for the rare times the network is down or inaccessible. There are two fields I need to update, counted and DateStamp. Counted is True/False and datecounted is a date field. The SQL below works on the True/false, but I need the actual value in the tblInvTemp.DateStamp not the current date . Any help would be appreciated.


    Code:
    UPDATE tblInvTemp INNER JOIN tblInv ON tblInvTemp.ID = tblInv.ID
    SET tblInv.Counted = True, tblInv.DateStamp = Date()
    WHERE (((tblInvTemp.Counted)=True) AND ((tblInvTemp.DateStamp)=Date()));

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    Where would you get that Date????
    If you are updating
    tblInv.DateStamp

    where is the value coming from?

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    SET tblInv.Counted = True, tblInv.DateStamp = tblInvTemp.DateStamp

    Will the value of DateStamp be the same for all records in tblInvTemp? If so then this filter criteria is not needed. Otherwise, you need to provide the date value to filter on. This can be statically configured in the query or input by a popup prompt (which I NEVER use) or reference to a form control. As is, the update will only occur for records with a DateStamp that is equal to current date.
    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.

  4. #4
    Access_Blaster is offline User
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2010
    Posts
    339
    Quote Originally Posted by orange View Post
    Where would you get that Date????
    If you are updating
    tblInv.DateStamp

    where is the value coming from?
    Sorry, the date is being generated from my print button.

    Code:
       Private Sub cmdPrintTag_Click()   
        On Error GoTo Form_Err
    
    
        DoCmd.OpenReport "rptAssetTag_Temp", acViewNormal
    
    
        CurrentDb.Execute "UPDATE tblInvTemp SET Counted = 1 WHERE ID = " & Forms!FRM_SearchMulti_Temp!SearchResults.Column(0), dbFailOnError Or dbSeeChanges
        CurrentDb.Execute "UPDATE tblInvTemp SET DateStamp = Date() WHERE ID = " & Forms!FRM_SearchMulti_Temp!SearchResults.Column(0), dbFailOnError Or dbSeeChanges
    
    
        Me.SearchResults.Requery
        Me.SearchFor.SetFocus
    
    
    Form_Exit:
        Exit Sub
    
    
    Form_Err:
        MsgBox err.Description
        Resume Form_Exit
    End Sub
    Basically any dates in the temp table tblInvTemp should also be in the SQL table tblInvTemp.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    I am confused. If the date is already in tblInv, why do you need to UPDATE that field?
    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.

  6. #6
    Access_Blaster is offline User
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2010
    Posts
    339
    Quote Originally Posted by June7 View Post
    I am confused. If the date is already in tblInv, why do you need to UPDATE that field?
    Code:
    Private Sub cmdPrintTag_Click()       On Error GoTo Form_Err
    
    
        DoCmd.OpenReport "rptAssetTag_Temp", acViewNormal
    
    
        CurrentDb.Execute "UPDATE tblInvTemp SET Counted = 1 WHERE ID = " & Forms!FRM_SearchMulti_Temp!SearchResults.Column(0), dbFailOnError Or dbSeeChanges
        CurrentDb.Execute "UPDATE tblInvTemp SET DateStamp = Date() WHERE ID = " & Forms!FRM_SearchMulti_Temp!SearchResults.Column(0), dbFailOnError Or dbSeeChanges
    
    
        Me.SearchResults.Requery
        Me.SearchFor.SetFocus
    
    
    Form_Exit:
        Exit Sub
    
    
    Form_Err:
        MsgBox err.Description
        Resume Form_Exit End Sub

  7. #7
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    That is where I had the issue as well, June. Seems the value was already there, but maybe we're missing something.

  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
    53,633
    More confused. Your original post said "use a local temp table to update a SQL table". But now you show queries updating the local table.

    Exactly what is the issue?
    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
    Access_Blaster is offline User
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2010
    Posts
    339
    If I put a value (date) in a temp table (tblInvTemp) it does not exist in the main table (tblInv) , there for I need to update the main table if there is changes in the temp. I'll get it eventually thanks.

  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
    53,633
    Did my suggestion in post 3 not help?
    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.

  11. #11
    Access_Blaster is offline User
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2010
    Posts
    339
    Quote Originally Posted by June7 View Post
    Did my suggestion in post 3 not help?
    Yes, your suggestion in post#3 gave me
    the help I needed. Thank you both.

    June7
    SET tblInv.Counted = True, tblInv.DateStamp = tblInvTemp.DateStamp
    Code:
    UPDATE tblInvTemp INNER JOIN tblInv ON tblInvTemp.ID = tblInv.ID
    SET tblInv.Counted = [tblInvTemp].[Counted], tblInv.DateStamp = tblInvTemp.DateStamp
    WHERE (((tblInvTemp.Counted)=True));

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

Similar Threads

  1. Replies: 14
    Last Post: 08-12-2014, 06:33 AM
  2. Replies: 7
    Last Post: 08-26-2013, 06:05 AM
  3. Replies: 2
    Last Post: 08-30-2012, 07:59 AM
  4. Replies: 4
    Last Post: 11-10-2011, 03:41 PM
  5. Replies: 1
    Last Post: 08-19-2011, 12:16 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