J
JRough
How can I test this script to make sure it works as expected? It runs
successfully through the script and I get a message that the compact
was successful. However, I don't see it go through the process to
copy the temporary backend file and then rename it and delete the
original db? I have to guarentee myself it is working and you would
think I could see vbscript doing the File manipulations. I think
there is some logic missing and it is not working.
tnx,
Option Explicit
Dim objscript
Dim dbe
set dbe = createobject("dao.dbengine.36")
'path is to System.mdb because it is a split database
dbe.SystemDB="Z:\SwimClub\System.mdw"
dbe.DefaultUser = "Brian"
dbe.DefaultPassword ="Kiyote#3"
On Error GoTo 0
'perform db compact of backend mdb into a temp mdb first
'if there is a problem the origial mdb is preserved
dbe.CompactDatabase"Z:\SwimClub\acsc_be.mdb","Z:\SwimClub
\temp_acsc_be.mdb",,,";pwd=Kiyote#3"
If (Err.Number <> 0) Then
On Error GoTo 0
' There was an error. Inform the user and halt execution
strMsg = "The following error was encountered while
compactingdatabase:"
strMsg = strMsg & vbCrLf & vbCrLf & Err.Description
Call MsgBox(strMsg)
Wscript.Quit
End If
On Error GoTo 0
' 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 "Z:\SwimClub\acsc_be.mdb", "Z:\SwimClub
\acsc_be.mdb" & "z", True
' Copy the compacted mdb by into the original file name
objScript.CopyFile "Z:\SwimClub\temp_acsc_be.mdb", "Z:\SwimClub
\acsc_be.mdb", True
' We are finished with TempDB. Kill it.
objScript.DeleteFile "Z:\SwimClub\temp_acsc_be.mdb"
Call MsgBox("compact successful")
successfully through the script and I get a message that the compact
was successful. However, I don't see it go through the process to
copy the temporary backend file and then rename it and delete the
original db? I have to guarentee myself it is working and you would
think I could see vbscript doing the File manipulations. I think
there is some logic missing and it is not working.
tnx,
Option Explicit
Dim objscript
Dim dbe
set dbe = createobject("dao.dbengine.36")
'path is to System.mdb because it is a split database
dbe.SystemDB="Z:\SwimClub\System.mdw"
dbe.DefaultUser = "Brian"
dbe.DefaultPassword ="Kiyote#3"
On Error GoTo 0
'perform db compact of backend mdb into a temp mdb first
'if there is a problem the origial mdb is preserved
dbe.CompactDatabase"Z:\SwimClub\acsc_be.mdb","Z:\SwimClub
\temp_acsc_be.mdb",,,";pwd=Kiyote#3"
If (Err.Number <> 0) Then
On Error GoTo 0
' There was an error. Inform the user and halt execution
strMsg = "The following error was encountered while
compactingdatabase:"
strMsg = strMsg & vbCrLf & vbCrLf & Err.Description
Call MsgBox(strMsg)
Wscript.Quit
End If
On Error GoTo 0
' 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 "Z:\SwimClub\acsc_be.mdb", "Z:\SwimClub
\acsc_be.mdb" & "z", True
' Copy the compacted mdb by into the original file name
objScript.CopyFile "Z:\SwimClub\temp_acsc_be.mdb", "Z:\SwimClub
\acsc_be.mdb", True
' We are finished with TempDB. Kill it.
objScript.DeleteFile "Z:\SwimClub\temp_acsc_be.mdb"
Call MsgBox("compact successful")