Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Sub SaveSnapshot()
- If Not BasicInclude.DebugMode Then On Error GoTo Error_Handler Else On Error GoTo 0
- Dim fs As New IWshRuntimeLibrary.FileSystemObject
- Dim fn As String
- Dim aob As AccessObject
- With CurrentData
- ' "Tables"
- For Each aob In .AllTables
- If aob.IsLoaded Then
- DoCmd.Close acTable, aob.Name, acSaveNo
- End If
- Next aob
- ' "Queries"
- For Each aob In .AllQueries
- If aob.IsLoaded Then
- DoCmd.Close acQuery, aob.Name, acSaveYes
- End If
- Next aob
- End With
- With CurrentProject
- ' "Forms"
- For Each aob In .AllForms
- If aob.IsLoaded Then
- 'If aob.Name Like "*switchboard*" Then
- 'Debug.Print "skipped switchboard"
- 'Else
- DoCmd.Close acForm, aob.Name, acSaveYes
- 'End If
- End If
- Next aob
- ' "Reports"
- For Each aob In .AllReports
- If aob.IsLoaded Then
- DoCmd.Close acReport, aob.Name, acSaveYes
- End If
- Next aob
- ' "Pages"
- For Each aob In .AllDataAccessPages
- If aob.IsLoaded Then
- DoCmd.Close acDataAccessPage, aob.Name, acSaveYes
- End If
- Next aob
- ' "Macros"
- For Each aob In .AllMacros
- If aob.IsLoaded Then
- DoCmd.Close acMacro, aob.Name, acSaveYes
- End If
- Next aob
- ' "Modules"
- For Each aob In .AllModules
- If aob.IsLoaded Then
- DoCmd.Close acModule, aob.Name, acSaveYes
- End If
- Next aob
- End With
- fn = Application.CurrentProject.Path & "\" & Split(Application.CurrentProject.Name, ".")(0) & " " & Format(Now, "YYYY MMM DD h m s am/pm") & "." & Split(Application.CurrentProject.Name, ".")(1)
- fs.CopyFile Application.CurrentDb.Name, fn
- MsgBox "File Created at:" & vbCrLf & fn, vbInformation + vbOKOnly
- 'Application.CurrentDb.Name
- error_exit:
- Set fs = Nothing
- Exit Sub
- Error_Handler:
- MsgBox "The following error has occured" & vbCrLf & vbCrLf & _
- "Error Number: " & Err.Number & vbCrLf & _
- "Error Source: SaveSnapshot" & vbCrLf & _
- "Error Description: " & Err.Description _
- , vbOKOnly + vbCritical, "An Error has Occured!"
- Resume error_exit
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment