Hi TM<br><br>You can't use the CompactDatabase method to compact an open database, so you need a bit more code.<br><br>I've just done this for an application I'm developing, which consists of a front-end db and a back-end db for data (Access 97). Below is the code to compact the front-end database, compact the back-end database, and then back-up the back-end db. I put them in a module, and then run them from a switchboard made with the switchboard manager.<br><br>For more on the Back-up function, check out<br> <A HREF="
TARGET="_new">
this helps.<br><br>Function DoCompression()<br>'Compact the front-end (open) Database<br> SendKeys ("%(TDC)"

<br> End Function<br><br>Public Sub Backup()<br>'This function backs up to the g: drive, you can back up to any location,<br>'just change the strDest Value<br><br> Dim db As Database<br> Dim strSource As String, strDest As String, strError As String<br> Dim strDate As String, strDateX As String<br><br> If MsgBox("Are you sure you want to back up data?", vbQuestion + vbYesNo, " Continue with Data Back-Up?"

= vbYes Then<br>'Un-comment the following 3 lines for a new backup for every day<br>'strDate = Format(Date, "mm/dd/yy"

<br>'strDateX = Left(strDate, 2) & Mid(strDate, 4, 2) & Right(strDate, 2)<br>'strDest = "a:\" & strDateX<br><br> Set db = CurrentDb()<br> DoCmd.Hourglass True<br><br>'Put any table name in here that exists in your back-end<br> strSource = db.TableDefs("YourTable"

.Connect<br> strSource = Mid(strSource, 11, Len(strSource) - 10)<br><br>'If you are using a new back-up every day, un-comment this line and replace the database name, and comment out the next line down<br>'strDest = strDest & "_YourBackEndDBNameHere.mdb"<br><br>'Replace with your database Back-end name<br> strDest = "g:\PathStatement\Back-Up Files\YourFile.mdb"<br>'Copy the file<br> FileCopy strSource, strDest<br><br> db.Close<br><br> DoCmd.Hourglass False<br> MsgBox ("Backup to " & vbNewLine & strDest & vbNewLine & " is Complete"

<br> End If<br><br>Exit_Backup:<br> Exit Sub<br><br>Err_Backup:<br>'Display appropriate Error Message<br> Select Case Err.Number<br> Case 61<br> strError = "Floppy disk is full" & vbNewLine & "cannot export mdb"<br> MsgBox strError, vbCritical, " Disk Full"<br> Kill strDest<br> Case 70<br> strError = "File is open" & vbNewLine & "cannot export mdb"<br> MsgBox strError, vbCritical, " File Open"<br> Case 71<br> strError = "No disk in drive" & vbNewLine & "please insert disk"<br> MsgBox strError, vbCritical, " No Disk"<br> Case Else<br> Err.Raise Err.Number, Err.Description<br> End Select<br><br> DoCmd.Hourglass False<br> Resume Exit_Backup<br><br>End Sub<br><br>Function DoCompressData()<br>'Compact the Back-End Data database<br> Dim strSource, strDest, strCompress As String<br>'Set the path names for the original file and the temporary file to compact to<br> strSource = "g:\PathStatement\Original File.mdb"<br> strCompress = "G:\PathStatement\TemporaryFile.mdb"<br> strDest = "g:\PathStatement\Original File.mdb<br><br> If MsgBox("Are you sure you want to compact the data?", vbQuestion + vbYesNo, " Continue with Data Compaction?"

= vbYes Then<br> DoCmd.Hourglass True<br> 'If the temp compact file exists, delete it<br> If Dir(strCompress) <> "" Then<br> Kill strCompress<br> End If<br> 'Compact the database<br> DBEngine.CompactDatabase strSource, strCompress<br> <br> 'Copy the temp file to the original filename and delete the temp file<br> FileCopy strCompress, strDest<br> Kill strCompress<br> DoCmd.Hourglass False<br> MsgBox ("Data Compaction is Complete"

<br> End If<br> <br>End Function<br><br>Lightning<br>