S
Santara
Ken Sheridan was kind enough to give me some new code (Shown at end) for the
process of Compacting the Backend from the Frontend. Following his
instructions I did the following:
First, I put Switchboard Items Table into the Front End.
Second, I created the standard module and called it CompactDatabase.
I imported the new code as he show it, entered the path to the Back End
file, and I ran Debug ->Compile.
Third, I created a new switchboard item called Compact Database Tables with
a Command of Run Code and the Function Name of CompactDatabase.
Finally, I went out to test it from the switchboard, and ran into a problem.
I got a critical message stating "There was an error executing the command."
And here....I'm lost. I don't know enough about VBA to figure out where the
problem is, or what to do next.
What do I do now?
Thanks for your help!
Santara
Here is the code provided by Ken:
Function CompactDatabase() 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
Const conBackEndFile = "F:\SomeFolder\SomeFile.mdb"
Dim booStatus As Boolean
Dim strBackupFile As String
booStatus = True
' Make sure that Back End File exists
If Len(Dir$(conBackEndFile)) = 0 Then
MsgBox "File " & conBackEndFile & " not found.", vbExclamation,
"Error"
booStatus = False
Else
' Figure out what the backup file should be named
If StrComp(Right$(conBackEndFile, 4), ".mdb", vbTextCompare) = 0 Then
strBackupFile = Left$(conBackEndFile, Len(conBackEndFile) - 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 conBackEndFile As strBackupFile
' Do the actual compact
DBEngine.CompactDatabase strBackupFile, conBackEndFile
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
process of Compacting the Backend from the Frontend. Following his
instructions I did the following:
First, I put Switchboard Items Table into the Front End.
Second, I created the standard module and called it CompactDatabase.
I imported the new code as he show it, entered the path to the Back End
file, and I ran Debug ->Compile.
Third, I created a new switchboard item called Compact Database Tables with
a Command of Run Code and the Function Name of CompactDatabase.
Finally, I went out to test it from the switchboard, and ran into a problem.
I got a critical message stating "There was an error executing the command."
And here....I'm lost. I don't know enough about VBA to figure out where the
problem is, or what to do next.
What do I do now?
Thanks for your help!
Santara
Here is the code provided by Ken:
Function CompactDatabase() 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
Const conBackEndFile = "F:\SomeFolder\SomeFile.mdb"
Dim booStatus As Boolean
Dim strBackupFile As String
booStatus = True
' Make sure that Back End File exists
If Len(Dir$(conBackEndFile)) = 0 Then
MsgBox "File " & conBackEndFile & " not found.", vbExclamation,
"Error"
booStatus = False
Else
' Figure out what the backup file should be named
If StrComp(Right$(conBackEndFile, 4), ".mdb", vbTextCompare) = 0 Then
strBackupFile = Left$(conBackEndFile, Len(conBackEndFile) - 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 conBackEndFile As strBackupFile
' Do the actual compact
DBEngine.CompactDatabase strBackupFile, conBackEndFile
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