Code for compact doesn't work.

S

SHIPP

I am working with Access 97 and have written the following code which doesn't
work.


Private Sub test()

Call subCompactDB("K:\SOX-HRPDB\ToManagers\HRP_Jacobson_Mike_1314.mdb")

End Sub

Private Sub subCompactDB(strCopyFrom As String)

On Error GoTo HandleErr
Const cstrProcName As String = "modCompactWrkDatabase - subCompactDB"

Dim strTmp As String

strTmp = Trim(strCopyFrom)
strTmp = Left(strCopyFrom, Len(strCopyFrom) - 4)
strTmp = strTmp & "BAK.mdb"

' Compact the database into a temporary database.
DBEngine.CompactDatabase strCopyFrom, strTmp

Kill strCopyFrom
Name strTmp As strCopyFrom

ExitHere:
Exit Sub

HandleErr:
Select Case Err.Number
Case 3356
MsgBox Err.Description & vbLf & _
"Please close all instances of this database" & _
"and try again."
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical,
cstrProcName
End Select

End Sub


The file HRP_Jacobson_Mike_1314.mdb expands to 17, 842 during processing.
When I use the code above it reduces to only 17,154. However, when I manually
compact the database it is reduced to 2,378. Does anybody know the reason for
this or can you see what I am doing wrong? I ran Sub subCompactDB from Sub
test to confirm that the variables were correct. Help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top