Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 32
  1. #16
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    For Forum Purposes, this is what the code should look like.


    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, Comments) " & _
    "IN ""C:\Documents and Settings\thorcc\Desktop\Database Work\InternalPostedPackageArchive.accdb"" " & _


    "SELECT PackageNumber, Program, FacilityArea, FacilityLocation, Comments FROM PkgsReceivedandScheduledStatus WHERE (Posted = True);"
    db.Execute strSql, dbFailOnError

    'Step 3: Execute the delete.
    strSql = "DELETE FROM PkgsReceivedandScheduledStatus 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

  2. #17
    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
    Thanks for sharing and marking the thread as Solved.

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

    Question Unsolved

    So I had to unsolve this thread because there is a problem with the code....or something...it's weird.

    Here is the 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, Comments) " & _
    "IN ""C:\Documents and Settings\thorcc\Desktop\Database Work\InternalPostedPackageArchive.accdb"" " & _
    "SELECT PackageNumber, Program, FacilityArea, FacilityLocation, Comments FROM PkgsReceivedandScheduledStatus WHERE (Posted = True);"
    db.Execute strSql, dbFailOnError

    'Step 3: Execute the delete.
    strSql = "DELETE FROM PkgsReceivedandScheduledStatus 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
    The code is written into the onclick event for a yes/no field.

    What is happening is when I select the yes no field to equal yes, the message box opens asking if I want to "Archive 0 record(s)". (figure1) Should be 1 record. I push ok anyway and and the confirm box goes away but nothing else happens. Record is not archived. I right click on the form and save form. Still Nothing. I then click the yes/no field to equal no and the confirm box opens again asking to "Archive 1 record(s)" (figure 2). I push ok and nothing....right click save, record gets archived.(figure3)

    Please help me with this because I am thoroughly confused.

    What I want to happen is I click to =yes and then confirm box opens. Click OK and record gets archived. No saving...extra clicks. Yes/OK done.

    I think what is happening is the yes from the form is not being written to the table before the rest of the code applies. Is there some code I can add to the beginning of the current on onlick event that saves the data to the table first and then goes through the rest of the code?
    Last edited by Desstro; 09-08-2010 at 03:32 AM.

  4. #19
    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
    If Me.Dirty Then Me.Dirty = False
    ...will save any current Dirty record.

  5. #20
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    Pardon my ignorance, but where should i put that in the code?

  6. #21
    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
    Right at the beginning of the executing code after all of the Dim statements. BTW, you used the "quote" tags instead of the "code" tags. "Code" tags preserve formatting (indenting) and "quote" tages do not.

  7. #22
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    I put that in after the DIM Statements and I get an error.

    Archiving Failed: Error 3218
    Could not update; currently locked.

    I'll paste the code in again.

    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.
      
      If Me.Dirty Then Me.Dirty = False
    
      '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, Comments) " & _
        "IN ""C:\Documents and Settings\thorcc\Desktop\Database Work\InternalPostedPackageArchive.accdb"" " & _
        "SELECT PackageNumber, Program, FacilityArea, FacilityLocation, Comments FROM PkgsReceivedandScheduledStatus WHERE (Posted = True);"
      db.Execute strSql, dbFailOnError
    
      'Step 3: Execute the delete.
      strSql = "DELETE FROM PkgsReceivedandScheduledStatus 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

  8. #23
    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
    Hmm...OK remove that code and add a test for:
    If Me.Posted Then
    .. your current code
    ..
    ..
    End If
    ...around all of the code.

  9. #24
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    I'm not quite sure what you mean by,

    "End If
    ...around all of the code."

  10. #25
    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
    This is what I mean:
    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.
       If Me.Posted Then
          '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, Comments) " & _
                   "IN ""C:\Documents and Settings\thorcc\Desktop\Database Work\InternalPostedPackageArchive.accdb"" " & _
                   "SELECT PackageNumber, Program, FacilityArea, FacilityLocation, Comments FROM PkgsReceivedandScheduledStatus WHERE (Posted = True);"
          db.Execute strSql, dbFailOnError
          'Step 3: Execute the delete.
          strSql = "DELETE FROM PkgsReceivedandScheduledStatus 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
       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

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

    Here's the code...

    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.
      If Me.Posted Then
    
      '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, Comments) " & _
        "IN ""C:\Documents and Settings\thorcc\Desktop\Database Work\InternalPostedPackageArchive.accdb"" " & _
        "SELECT PackageNumber, Program, FacilityArea, FacilityLocation, Comments FROM PkgsReceivedandScheduledStatus WHERE (Posted = True);"
      db.Execute strSql, dbFailOnError
    
      'Step 3: Execute the delete.
      strSql = "DELETE FROM PkgsReceivedandScheduledStatus 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
      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
    see image for what happens. back to "Archive o record(s) and I push ok and nothing.

  12. #27
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    Well i have to go now....thanks for your continuous support. Hopefully when I get back to work tomorrow there will be a golden answer to this perpetual problem.

    Thanks again...until tomorrow.

  13. #28
    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
    Posting your db would be very helpful for us to troubleshoot the issue with.

  14. #29
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    Ok, I came up with a simple solution.

    I removed the code from the onclick event from the yes/no field.

    I added a button to the header of the form and put the code in its onclick event.

    I added simple instructions to the form on how to perform its function. (see image)

    What I was trying to achieve now works like a dream.

    The code in the onclick event for the button is:

    Code:
    Private Sub Command17_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 (PostedDate, PackageNumber, Program, FacilityArea, FacilityLocation, Comments) " & _
        "IN ""C:\Documents and Settings\thorcc\Desktop\Database Work\InternalPostedPackageArchive.accdb"" " & _
        "SELECT PostedDate, PackageNumber, Program, FacilityArea, FacilityLocation, Comments FROM PkgsReceivedandScheduledStatus WHERE (Posted = True);"
      db.Execute strSql, dbFailOnError
    
      'Step 3: Execute the delete.
      strSql = "DELETE FROM PkgsReceivedandScheduledStatus 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
    What was wrong was, because the DB isn't updated by just checking the yes/no field on the form, the table that this code is written for did not show that the yes/no field had been modified by the form.

    This way the instructions are to modify the data. Save the data. Click submit which now runs the archive code.

    Problem solved as far as I'm concerned.

    I'm not quite sure how to upload my DB into here but if you don't mind explaining it to me I would be more than happy to.

    I tried with the "manage attachments", but the file type was not supported.

  15. #30
    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
    Compact and Repair your db first and then zip it up before uploading.

Page 2 of 3 FirstFirst 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