J
Janis
I got this script from database journal. I put this script in a new
module. I have Access 2000 so I changed it to application9. I put in the
path.
I click run->sub/UserForm and it brings up an empty macro window? I don't
know why it doesn't compile and it tries to bring up a macro window. Is it
supposed to be attached to a form or to the database object ? I would like
it to run anytime the database closes from the close box or from the close
macros on the toolbar. There is a simple macro called ExitProgram with
the action "Quit" this is attached to a toolbar. I can't find where the
toolbar is created. It is not in form design. Can you get me started on
using this script? I don't know if I should attach this script to a macro in
the toolbar but probably not just have it run before the database closes. I
just wanted to see if the script would run or give me an error message. It
is not working because it is VBS not VBA? Is that the problem?
thanks,
Option Compare Database
' ***************** 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:\SwimClubDev\acsc.mdb"
'
' ////////////////////////////////////////////////////////////////
' Set a name and path for a temporary mdb file
strTempDB = "C:\Comp0001.mdb"
' Create Access 97 Application Object
Set objAccess = CreateObject("Access.Application.9")
' For Access 2000, use Application.9
'Set objAccess = CreateObject("Access.Application.9")
' 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
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 ' ******************
Thanks,
module. I have Access 2000 so I changed it to application9. I put in the
path.
I click run->sub/UserForm and it brings up an empty macro window? I don't
know why it doesn't compile and it tries to bring up a macro window. Is it
supposed to be attached to a form or to the database object ? I would like
it to run anytime the database closes from the close box or from the close
macros on the toolbar. There is a simple macro called ExitProgram with
the action "Quit" this is attached to a toolbar. I can't find where the
toolbar is created. It is not in form design. Can you get me started on
using this script? I don't know if I should attach this script to a macro in
the toolbar but probably not just have it run before the database closes. I
just wanted to see if the script would run or give me an error message. It
is not working because it is VBS not VBA? Is that the problem?
thanks,
Option Compare Database
' ***************** 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:\SwimClubDev\acsc.mdb"
'
' ////////////////////////////////////////////////////////////////
' Set a name and path for a temporary mdb file
strTempDB = "C:\Comp0001.mdb"
' Create Access 97 Application Object
Set objAccess = CreateObject("Access.Application.9")
' For Access 2000, use Application.9
'Set objAccess = CreateObject("Access.Application.9")
' 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
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 ' ******************
Thanks,