Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

automatic dbase compacting

Status
Not open for further replies.

roddy17

Technical User
Jul 27, 2001
49
0
0
CA
Hi
i found some code on a website that talks about automatically compacting an Access database. I cannot find any method of replying to them however. So i am asking you if you can tell me where i should put this code. Does it get placed somewhere within my database, or is it external to my Access Database but somewhere within the same network drive?
Here is the segment that i got from the website:

Dim objScript
Dim objAccess
Dim strPathToMDB
Dim strMsg

' ////// NOTE: User must edit variables in this section //////'
' The following lines of code are the only variable that need
' be edited. You must provide a path to the Access MDB which
' will be compacted, but the other path needs only be edited
' if desired (it points to temp files)'

strPathToMDB = "H:\EMSEnt.mdb"
strTempDB = "H:\Comp0001.mdb"'

' ////////////////////////////////////////////////////////////////

' Create Access 97 Application Object
Set objAccess = CreateObject("Access.Application.8")

' For Access 2000, use Application.9
'Set objAccess = CreateObject("Access.Application.9")

objAccess.DbEngine.CompactDatabase strPathToMDB ,strTempDB
Set objScript= CreateObject("Scripting.FileSystemObject")

objScript.CopyFile strPathToMDB , strPathToMDB & "z", True
objScript.CopyFile strTempDB, strPathToMDB, True
objScript.DeleteFile strTempDB
' Clean up
Set objAccess = Nothing
Set objScript = Nothing

thanks...........roddy
 
You would put this code into a separate module within a database. HOWEVER, this code will not compact the (open) database from which it is run. It can only be used to compact another database
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top