Compact repair data.vbs: Difference between revisions
Jump to navigation
Jump to search
Ttenbergen (talk | contribs) No edit summary |
Ttenbergen (talk | contribs) m →dev history: removed broken old links |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
this is now done by the Sub compact_runner(). Reference only. | |||
This could be run by a scheduled task or called otherwise... but not from inside Access because then the .mdb would still be open. | This could be run by a scheduled task or called otherwise... but not from inside Access because then the .mdb would still be open. | ||
So, it needs to become part of the news and backup.bat. Good thing we need to roll out a new one. | So, it needs to become part of the news and backup.bat. Good thing we need to roll out a new one. | ||
We have a file [[Regional Server]]\Maintenance\compact_repair_data.vbs with the following code. I am putting the code here because it was a pain to find and I want to have a backup. :-) | |||
' ***************** BEGIN CODE HERE ' ***************** | ' ***************** BEGIN CODE HERE ' ***************** | ||
Line 14: | Line 16: | ||
' | ' | ||
' The following line of code is the only variable that need be edited | ' The following line of code is the only variable that need be edited | ||
' You must provide a path to the Access MDB which will be compacted | ' You must provide: | ||
' a path to the Access MDB which will be compacted | |||
strPathToMDB = "C:\ccmdb_data\ccmdb_data.mdb" | strPathToMDB = "C:\ccmdb_data\ccmdb_data.mdb" | ||
' | |||
' a name and path for a temporary mdb file | |||
strTempDB = "C:\ccmdb_data\tmp.mdb" | |||
' | |||
' For Access 2003, use Application.11 | |||
Set objAccess = CreateObject("Access.Application.11") | |||
' | ' | ||
' //////////////////////////////////////////////////////////////// | ' //////////////////////////////////////////////////////////////// | ||
' | ' | ||
' | ' | ||
' Perform the DB Compact into the temp mdb file | ' Perform the DB Compact into the temp mdb file | ||
Line 56: | Line 59: | ||
[[Category: Batch Files]] | [[Category: Batch Files]] | ||
[[Category:IT Instructions]] | [[Category:IT Instructions]] |
Latest revision as of 17:17, 2021 December 22
this is now done by the Sub compact_runner(). Reference only.
This could be run by a scheduled task or called otherwise... but not from inside Access because then the .mdb would still be open. So, it needs to become part of the news and backup.bat. Good thing we need to roll out a new one.
We have a file Regional Server\Maintenance\compact_repair_data.vbs with the following code. I am putting the code here because it was a pain to find and I want to have a backup. :-)
' ***************** BEGIN CODE HERE ' ***************** ' Dim objScript Dim objAccess Dim strPathToMDB Dim strMsg ' ' ///////////// NOTE: User must edit variables in this section ///// ' ' The following line of code is the only variable that need be edited ' You must provide: ' a path to the Access MDB which will be compacted strPathToMDB = "C:\ccmdb_data\ccmdb_data.mdb" ' ' a name and path for a temporary mdb file strTempDB = "C:\ccmdb_data\tmp.mdb" ' ' For Access 2003, use Application.11 Set objAccess = CreateObject("Access.Application.11") ' ' //////////////////////////////////////////////////////////////// ' ' ' Perform the DB Compact into the temp mdb file ' (If there is a problem, then the original mdb is preserved) objAccess.DbEngine.CompactDatabase strPathToMDB,strTempDB,,,";pwd=4Cookies" ' If Err.Number > 0 Then ' There was an error. Inform the user and halt execution strMsg = "The following error was encountered while compacting database:" strMsg = strMsg & vbCrLf & vbCrLf & Err.Description Else ' Create File System Object to handle file manipulations Set objScript= CreateObject("Scripting.FileSystemObject") ' Back up the original file as Filename.mdbz. In case of undetermined ' error, it can be recovered by simply removing the terminating "z". objScript.CopyFile strPathToMDB , strPathToMDB & "z", True ' ' Copy the compacted mdb by into the original file name objScript.CopyFile strTempDB, strPathToMDB, True ' ' We are finished with TempDB. Kill it. objScript.DeleteFile strTempDB End If ' ' Always remember to clean up after yourself Set objAccess = Nothing Set objScript = Nothing ' ' ****************** END CODE HERE ' ******************