KySoto

saveSnapshot

Aug 15th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Sub SaveSnapshot()
  2.     If Not BasicInclude.DebugMode Then On Error GoTo Error_Handler Else On Error GoTo 0
  3.     Dim fs As New IWshRuntimeLibrary.FileSystemObject
  4.     Dim fn As String
  5.     Dim aob As AccessObject
  6.     With CurrentData
  7.         ' "Tables"
  8.        For Each aob In .AllTables
  9.             If aob.IsLoaded Then
  10.                 DoCmd.Close acTable, aob.Name, acSaveNo
  11.             End If
  12.         Next aob
  13.  
  14.         ' "Queries"
  15.        For Each aob In .AllQueries
  16.             If aob.IsLoaded Then
  17.                 DoCmd.Close acQuery, aob.Name, acSaveYes
  18.             End If
  19.         Next aob
  20.     End With
  21.  
  22.  
  23.     With CurrentProject
  24.         ' "Forms"
  25.        For Each aob In .AllForms
  26.             If aob.IsLoaded Then
  27.                 'If aob.Name Like "*switchboard*" Then
  28.                'Debug.Print "skipped switchboard"
  29.                'Else
  30.                DoCmd.Close acForm, aob.Name, acSaveYes
  31.                 'End If
  32.            End If
  33.         Next aob
  34.  
  35.         ' "Reports"
  36.        For Each aob In .AllReports
  37.             If aob.IsLoaded Then
  38.                 DoCmd.Close acReport, aob.Name, acSaveYes
  39.             End If
  40.         Next aob
  41.  
  42.         ' "Pages"
  43.        For Each aob In .AllDataAccessPages
  44.             If aob.IsLoaded Then
  45.                 DoCmd.Close acDataAccessPage, aob.Name, acSaveYes
  46.             End If
  47.         Next aob
  48.  
  49.         ' "Macros"
  50.        For Each aob In .AllMacros
  51.             If aob.IsLoaded Then
  52.                 DoCmd.Close acMacro, aob.Name, acSaveYes
  53.             End If
  54.         Next aob
  55.  
  56.         ' "Modules"
  57.        For Each aob In .AllModules
  58.             If aob.IsLoaded Then
  59.                 DoCmd.Close acModule, aob.Name, acSaveYes
  60.             End If
  61.         Next aob
  62.     End With
  63.     fn = Application.CurrentProject.Path & "\" & Split(Application.CurrentProject.Name, ".")(0) & " " & Format(Now, "YYYY MMM DD h m s am/pm") & "." & Split(Application.CurrentProject.Name, ".")(1)
  64.     fs.CopyFile Application.CurrentDb.Name, fn
  65.     MsgBox "File Created at:" & vbCrLf & fn, vbInformation + vbOKOnly
  66.     'Application.CurrentDb.Name
  67.  
  68. error_exit:
  69.     Set fs = Nothing
  70.     Exit Sub
  71. Error_Handler:
  72.     MsgBox "The following error has occured" & vbCrLf & vbCrLf & _
  73.            "Error Number: " & Err.Number & vbCrLf & _
  74.            "Error Source: SaveSnapshot" & vbCrLf & _
  75.            "Error Description: " & Err.Description _
  76.            , vbOKOnly + vbCritical, "An Error has Occured!"
  77.     Resume error_exit
  78. End Sub
Advertisement
Add Comment
Please, Sign In to add comment