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

How to rename a closed .mdb? 1

Status
Not open for further replies.

genomon

Programmer
Aug 20, 2001
2,449
US
I have an app to compact backend.mdb's automatically overnight. The CompactDatabase method creates a compacted copy with a new name. After doing a Kill of the old (uncompacted) .mdb, I need to find out how to rename the new compacted .mdb back to its old name with VBA code.
CreateDatabase will not work, as I don't want it to open.
Just need to (programmatically) change the name. Found lots of stuff that applies to objects WITHIN a db (Name, ReName, etc) but nothing for an entire db. Even TransferDatabase requires an object parameter (table, report, etc). Likely this is something so simple, it's embarrassing.....
Any help is appreciated!!
-Geno
 
Try this function in a new module.

Function DoCompressData()
On Error GoTo Err_DoCompressData

'Compact the Back-End Data database
Dim strSource, strDest, strCompress As String
'Set the path names for the original file and the temporary file to compact to
strSource = "S:\Your PathName\YourOriginalDb.mdb"
strCompress = "S:\Your PathName\Compressed Data.mdb"
strDest = "S:\Your PathName\YourNewDb.mdb"

If Msgbox("Are you sure you want to compact the data?", vbQuestion + vbYesNo, " Continue with Data Compaction?") = vbYes Then
DoCmd.hourglass True
'If the temp compact file exists, delete it
If Dir(strCompress) <> &quot;&quot; Then
Kill strCompress
End If
'Compact the database
DBEngine.CompactDatabase strSource, strCompress

'Copy the temp file to the original filename and delete the temp file
FileCopy strCompress, strDest '<--- Note This Line
Kill strCompress
DoCmd.hourglass False
Msgbox (&quot;Data Compaction is Complete&quot;)
End If

Exit_DoCompressData:
DoCmd.hourglass False
Exit Function

Err_DoCompressData:
DoCmd.hourglass False
If Err.Number = 3356 Then
Msgbox &quot;Another User has the Tracker Data files Open.&quot; & vbCrLf & _
&quot;You cannot Compact the data tables at this time.&quot;, vbOKOnly + vbExclamation, _
&quot;Compress Function not available&quot;
Resume Exit_DoCompressData
Else
Err.Raise Err.Number, Err.Description
Resume Exit_DoCompressData
End If
End Function

HTH

Lightning
 
Thanks Lightning!
For some retentive reason on my part, I was thinking that FileCopy would not be the answer. Forgot the .mdb is a FILE extension just like everything else! Thanks for your time and for waking me up!!
-Geno
 
Jim:
Get a page fault (ACC97) until the original filename is free (deleted).
-Gman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top