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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compact DB Issue

Status
Not open for further replies.

Cleis

Technical User
Jun 4, 2000
197
US
Hi group!

I can really use some help! I've got a database that I've created that needs to be compacted on a regular basis (large record imports and deletes). So I've created another database (Compact.mdb) from where I will compact and repair the Master DB in this case MrkDB.mdb. I've written the code listed below to open the Compact.mdb. but I can't figure out how to close MrkDB.mdb? Further, I would like to delete the old MrkDB.mdb and rename the newly compacted databse with the same old name! That way my users shortcuts will still work. Am I asking too much? Please keep in mind that I'm a VBA wanna be! I just can't fint the right answers in any of my numerous Access VBA books!

Option Compare Database
Option Explicit
Dim appAccess As Access.Application

Function OpenDB()

Dim strDB As String

strDB = "C:\MrkDB\Compact.mdb "

Set appAccess = CreateObject("Access.Application.8")


appAccess.OpenCurrentDatabase strDB
appAccess.DoCmd.OpenForm "frmCompact", acNormal, , , , acWindowNormal






End Function
 
Hi,
The following will close the open database:

appAccess.CloseCurrentDatabase
Set appAccess = Nothing

You can delete a file with the Kill command:

Kill "MrkDB.mdb"
or
Kill "*.mdb"

And since I forgot how to rename files. Here is the text from the VB6 help files:

Name Statement Example
This example uses the Name statement to rename a file. For purposes of this example, assume that the directories or folders that are specified already exist.

Dim OldName, NewName
OldName = "OLDFILE": NewName = "NEWFILE" ' Define file names.
Name OldName As NewName ' Rename file.

OldName = "C:\MYDIR\OLDFILE": NewName = "C:\YOURDIR\NEWFILE"
Name OldName As NewName ' Move and rename file.

That should do it =)

Rob Marriott
rob@career-connections.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top