Results 1 to 5 of 5
  1. #1
    Moosee is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2023
    Posts
    9

    Cannot get tables or database to save off without getting errors, none of the DoCmd's work for me


    Code:
    Private Sub cmdRolloverData_Click()
       
       Dim Answer As String
       Dim TargetPath As String
       Dim ArchiveDBName As String
       Dim aApp As Access.Application
       Dim dbPathAndName As String
       Dim db As DAO.Database
       
       On Error GoTo RolloverError
       
       Answer = MsgBox("Are you sure you want to archive/rollover the 'Current/Prior Year' rate data?", vbQuestion + vbYesNo, "???")
       
       If Answer = vbYes Then
       
          DoCmd.Hourglass True
          Application.Echo False
       
          TargetPath = Application.CurrentProject.Path
          ArchiveDBName = "CRASuspense_Archive_" & Format(Now, "yyyymmdd") & ".accdb"
          dbPathAndName = TargetPath & "\" & ArchiveDBName
          Set aApp = New Access.Application
          aApp.NewCurrentDatabase dbPathAndName, acNewDatabaseFormatUserDefault
          aApp.Quit
          DoCmd.SetWarnings False
          DoCmd.CopyObject dbPathAndName, "tblCurrentYear", acTable, "tblCurrentYear"
          DoCmd.CopyObject dbPathAndName, "tblPriorYear", acTable, "tblPriorYear"
    '      DoCmd.CopyDatabaseFile DatabaseFileName:=dbPathAndName, OverwriteExistingFile:=True, DisconnectAllUsers:=False
          DoCmd.SetWarnings True
          
          Set db = CurrentDb
          ' Finish cleaning up the Prior and Current Year tables
          CurrentDb.Execute "qry_Rollover_Delete_PriorYear"
          CurrentDb.Execute "qry_Rollover_Append_CurrentYear_to_PriorYear"
          CurrentDb.Execute "qry_Rollover_Delete_CurrentYear"
          CurrentDb.Execute "qry_Rollover_Update_tblFiscalYear"
          CurrentDb.Execute "qry_Rollover_Update_tblPeriod"
          
          DoCmd.Hourglass False
          Application.Echo True
          
          MsgBox "The Archive/Rollover is finished.  The Archive database is " & dbPathAndName
          
       End If
       Exit Sub
    RolloverError:
     '  MsgBox "There was a error while trying to Archive/Rollover."
       MsgBox Err.Description
       Application.Echo True
       DoCmd.Hourglass False
    
    
    End Sub

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,933
    Works for me?
    Would have to ask why set db = CurrentDb and then use Currentdb.Execute ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Moosee is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2023
    Posts
    9
    Just a mistake that needs to be fixed. Thank you.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    So it's all good now? vbYes data type is Long Integer but you're assigning it to a string variable. I think I can see why it works, but it's a dicey way to code it. Better to make the variable an integer or a long.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Moosee is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2023
    Posts
    9
    Ok, thanks, I will fix, but that is not what is giving me the problem.

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

Similar Threads

  1. Replies: 4
    Last Post: 01-29-2021, 01:19 PM
  2. Replies: 6
    Last Post: 08-12-2019, 05:02 PM
  3. Replies: 1
    Last Post: 01-28-2018, 10:51 PM
  4. Replies: 4
    Last Post: 06-21-2014, 05:43 AM
  5. Replies: 1
    Last Post: 03-08-2012, 08:34 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