S
Santara
I found a post from 10/22/2004 that gave the code (shown at end) for this
posted by Doug Steele.
I am new to using VBA code, so my question is "Where" do I put this code.
What do I do to get this to work? I am using the built in switchboard and
would like to have it run from there. If I use the switchboard, do I create
an unbound form with a command button to activate the code? If so, does that
make it an Event Procedure?
OR.... is there a way to just use this code to compact and repair the front
end on the close of the database. There is a single user for the database,
so we don't have the problem of someone else using the table when she closes
out.
Thanks for the help!
Santara
--------------------------------------------------
Here is the Code copied from previous post:
Function CompactDatabase(DatabaseName As String) As Boolean
' Renames the existing backend database from .MDB to .BAK
' Compacts the backup copy to the "proper" database
'
' Returns True if successful, False otherwise
On Error GoTo Err_CompactDatabase
Dim booStatus As Boolean
Dim strBackupFile As String
booStatus = True
' Make sure that DatabaseName exists
If Len(Dir$(DatabaseName)) > 0 Then
' Figure out what the backup file should be named
If StrComp(Right$(DatabaseName, 4), ".mdb", vbTextCompare) = 0 Then
strBackupFile = Left$(DatabaseName, Len(DatabaseName) - 4) &
".bak"
' Determine whether the backup file already exists,
' and delete it if it does.
If Len(Dir$(strBackupFile)) > 0 Then
Kill strBackupFile
End If
Name DatabaseName As strBackupFile
' Do the actual compact
DBEngine.CompactDatabase strBackupFile, DatabaseName
End If
End If
End_CompactDatabase:
CompactDatabase = booStatus
Exit Function
Err_CompactDatabase:
booStatus = False
MsgBox Err.Description & " (" & Err.Number & ")", _
vbOkOnly + vbCritical
Resume End_CompactDatabase
End Function
posted by Doug Steele.
I am new to using VBA code, so my question is "Where" do I put this code.
What do I do to get this to work? I am using the built in switchboard and
would like to have it run from there. If I use the switchboard, do I create
an unbound form with a command button to activate the code? If so, does that
make it an Event Procedure?
OR.... is there a way to just use this code to compact and repair the front
end on the close of the database. There is a single user for the database,
so we don't have the problem of someone else using the table when she closes
out.
Thanks for the help!
Santara
--------------------------------------------------
Here is the Code copied from previous post:
Function CompactDatabase(DatabaseName As String) As Boolean
' Renames the existing backend database from .MDB to .BAK
' Compacts the backup copy to the "proper" database
'
' Returns True if successful, False otherwise
On Error GoTo Err_CompactDatabase
Dim booStatus As Boolean
Dim strBackupFile As String
booStatus = True
' Make sure that DatabaseName exists
If Len(Dir$(DatabaseName)) > 0 Then
' Figure out what the backup file should be named
If StrComp(Right$(DatabaseName, 4), ".mdb", vbTextCompare) = 0 Then
strBackupFile = Left$(DatabaseName, Len(DatabaseName) - 4) &
".bak"
' Determine whether the backup file already exists,
' and delete it if it does.
If Len(Dir$(strBackupFile)) > 0 Then
Kill strBackupFile
End If
Name DatabaseName As strBackupFile
' Do the actual compact
DBEngine.CompactDatabase strBackupFile, DatabaseName
End If
End If
End_CompactDatabase:
CompactDatabase = booStatus
Exit Function
Err_CompactDatabase:
booStatus = False
MsgBox Err.Description & " (" & Err.Number & ")", _
vbOkOnly + vbCritical
Resume End_CompactDatabase
End Function