Page 1 of 3 123 LastLast
Results 1 to 15 of 32
  1. #1
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185

    Question Auto Archive Function

    I know this is not really necessary. I tried to talk sense into my boss but he want's it this way.

    How can I, when a yes/no box is checked, have that record deleted from its current table and copied to another, "archive" table?

    See image. Basically he wants is when the Posted field is checked, the PostedDate field is automatically filled in with the current system date and then the record to be moved to an archive table which will be called PostedPkgs.

    If it makes any difference the Pkeys are PackageNumber, Program, FacilityArea and FacilityLocation. Will be the same for the archive table.



    Code anyone?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You should find this link helpful: http://allenbrowne.com/ser-37.html

  3. #3
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185

    Archiving Failed Error 3131

    I have a form where my yes/no field is that I put this code in in the onclick event. It returne an "Archiving Failed Error 3131".

    The error states "Syntax Error in FROM Clause"

    Please help.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Why are you using the IN statement? Isn't your Archive table in the same mdb?

  5. #5
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    should it be? I pretty much just copied and pasted what was in the link you suggested and changed the data to match my DB. I created a new DB for archive but i don't see why not use same DB and delete archive annually.

    Can you help me with what the code should look like if using the same db with a table called InternalPostedPackageArchive?

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    It would actually be better if your archive were in another db but you need to specify the .Extent in the IN statement.

  7. #7
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    I'm not sure I understand. you mean something like "IN C:\Documents and Settings\thorcc\Desktop\Database Work"?

    I would like it to be a different DB.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Nope! Something like:
    "IN ""C:\Documents and Settings\thorcc\Desktop\Database Work.ACCDB"" "?
    ...and don't forget the EXTRA quotes!

  9. #9
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    Ok I'm going to give it a shot.

  10. #10
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185

    Getting a syntax error in the Insert INTO statement....

    Code:
    Private Sub Posted_Click()
    On Error GoTo Err_DoArchive
      Dim ws As DAO.Workspace   'Current workspace (for transaction).
      Dim db As DAO.Database    'Inside the transaction.
      Dim bInTrans As Boolean   'Flag that transaction is active.
      Dim strSql As String      'Action query statements.
      Dim strMsg As String      'MsgBox message.
     
      'Step 1: Initialize database object inside a transaction.
      Set ws = DBEngine(0)
      ws.BeginTrans
      bInTrans = True
      Set db = ws(0)
     
      'Step 2: Execute the append.
      strSql = "INSERT INTO InternalPostedPackageArchive ( PackageNumber, Program, FacilityArea, FacilityLocation, ) " & _
        "IN ""C:\C:\Documents and Settings\thorcc\Desktop\Database Work.InternalPostedPackageArchive.accdb"" " & _
        "SELECT PackageNumber, Program, FacilityArea, FacilityLocation FROM PkgcReceivedandScheduledStatus WHERE (Posted = True);"
      db.Execute strSql, dbFailOnError
     
      'Step 3: Execute the delete.
      strSql = "DELETE FROM PkgcReceivedandScheduledStatus WHERE (Posted = True);"
      db.Execute strSql, dbFailOnError
     
      'Step 4: Get user confirmation to commit the change.
      strMsg = "Archive " & db.RecordsAffected & " record(s)?"
      If MsgBox(strMsg, vbOKCancel + vbQuestion, "Confirm") = vbOK Then
        ws.CommitTrans
        bInTrans = False
      End If
     
    Exit_DoArchive:
      'Step 5: Clean up
      On Error Resume Next
      Set db = Nothing
      If bInTrans Then   'Rollback if the transaction is active.
        ws.Rollback
      End If
      Set ws = Nothing
    Exit Sub
     
    Err_DoArchive:
      MsgBox Err.Description, vbExclamation, "Archiving failed: Error " & Err.Number
      Resume Exit_DoArchive
     
    End Sub
    Last edited by RuralGuy; 09-07-2010 at 05:56 AM. Reason: Added Code Tags

  11. #11
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    I saw where I had C: in there twice, fixed it and still same error

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Your IN statement is still not correct! What is the FULL PATH to your Archive db?

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    C:\Documents and Settings\thorcc\Desktop\Database Work.InternalPostedPackageArchive.accdb
    The Highlighted part in not correct!

  14. #14
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185

    Talking

    Yup...fixed it. Actually fixed it before I read your last post so I am feeling better about myself now. Sorry, it's been a long night for me. I do appreciate your help and patience. Once again RuralGuy...you are the man!

  15. #15
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You'll notice I added code tags to your Post #10. Please use them in the future as it is *much* easier to read code that way.

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Delete button with archive Table
    By tlyons in forum Forms
    Replies: 4
    Last Post: 07-08-2010, 12:18 PM
  2. How do I archive a report?
    By Computer202 in forum Reports
    Replies: 7
    Last Post: 03-07-2010, 10:58 AM
  3. Archive and Compact function
    By dollygg in forum Access
    Replies: 3
    Last Post: 08-18-2009, 03:49 AM
  4. Want function to get current function name
    By Davis DeBard in forum Programming
    Replies: 2
    Last Post: 08-13-2009, 05:02 AM
  5. Archive data
    By markhook in forum Forms
    Replies: 0
    Last Post: 08-08-2006, 10:23 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