i appreciate your help but i am still a rooky at vb coding, and as a
result i am not astute enough to follow your suggestions. the first
thing i did was make a copy of the mda file and then tried to make
changes, so i would not totally screw up the mda file. i need very
specific instructions on how to fix. thanks
Replace these 2 routines and call the compact routine as
Call Application.Run("Compacter.docompact", True, "password")
' *** Code Start ***
Function DoCompact(ReStart As Boolean, Optional pwd As String)
Dim strCompacter As String
Dim strExePath As String
strExePath = SysCmd(acSysCmdAccessDir) & "msAccess.Exe"
strCompacter = Chr$(34) & CodeDb.Name & Chr$(34) _
& " /cmd" & " " & CurrentDb.Name
If ReStart = True Then
strCompacter = strCompacter & ";True"
Else
strCompacter = strCompacter & ";False"
End If
If (Len(pwd)) Then
strCompacter = strCompacter & ";" & pwd
End If
Call Shell(strExePath & " " & strCompacter, vbNormalFocus)
End Function
Function fCompactDatabase(strMDBNamePath As String) As Boolean
'*******************************************
'Name: fCompactDatabase (Function)
'Purpose: Close (if Open) and compact an external Jet Database
'Author: Dev Ashish
'Date: 04 November 1998
'Called by:
'Calls: API, TempFile
'Inputs: strMDBNamePath - full path to MDB file
'Output: True on success, False on failure
'*******************************************
On Error GoTo Err_Handler
Dim strMsg As String
Dim strFileOnly As String
Dim strNewFile As String
Dim intI As Integer
Dim strTmpName As String
Dim intPos As Integer, pos2 As Integer
Dim pwd As String
Dim objAccess As Access.Application
'Determine whether we need to reopen the source database or not
'See if the semi colon separater is there
intPos = InStr(1, strMDBNamePath, ";")
' Determine password, if present
pos2 = InStr(intPos + 1, strMDBNamePath, ";")
If intPos > 0 Then
'If string to the right is False, just close
If (pos2 > 0) Then
strTmpName = Mid$(strMDBNamePath, intPos + 1, pos2 - intPos)
Else
strTmpName = Right$(strMDBNamePath, Len(strMDBNamePath) -
intPos)
End If
If (pos2 > 0) Then
pwd = Mid$(strMDBNamePath, pos2 + 1)
End If
'get a clean name for strMDBNamePath
strMDBNamePath = Left$(strMDBNamePath, intPos - 1)
Select Case UCase(strTmpName)
Case "FALSE":
mblnReopen = False
Case "TRUE":
mblnReopen = True
Case Else:
'Assume the we have to reopen
mblnReopen = True
End Select
Else 'Assume we have to reopen if the option isn't there
mblnReopen = True
End If
'Invalid argument value
If Len(strMDBNamePath) = 0 Then Err.Raise mconERR_NO_COMMAND_LINE
'File doesn't exist
If Len(Dir(strMDBNamePath)) = 0 Then Err.Raise mconERR_FILE_NOT_EXIST
'strip out the filename from db path
strFileOnly = Dir$(strMDBNamePath)
'Get a unique filename to compact to
strNewFile = TempFile(False)
'Try to get a handle to the other Access instance
Do While objAccess Is Nothing
intI = intI + 1
If intI = 50 Then Err.Raise mconERR_INSTANCE_NOT_FOUND
Set objAccess = GetObject(strMDBNamePath)
DoEvents
Loop
'Close the database and compact it to a new file
'close all open objects
Call sCloseAllObjects(objAccess)
With objAccess
.CloseCurrentDatabase
Call sUpdateStatusForm("Compacting " & vbCrLf & strMDBNamePath &
vbCrLf _
& " to " & vbCrLf & strNewFile)
If (Len(pwd)) Then
'DBEngine.CompactDatabase strMDBNamePath, strNewFile,
";pwd=" & pwd
DBEngine.CompactDatabase strMDBNamePath, strNewFile, , ,
";pwd=" & pwd
Else
DBEngine.CompactDatabase strMDBNamePath, strNewFile
End If
DoEvents
Kill strMDBNamePath
DoEvents
Call sUpdateStatusForm("Copying " & vbCrLf & strNewFile & vbCrLf
_
& " to " & vbCrLf &
strMDBNamePath)
FileCopy strNewFile, strMDBNamePath
Do While Len(strMDBNamePath) = 0: DoEvents: Loop
'Only open if specified
If mblnReopen Then
If (Len(pwd)) Then
.OpenCurrentDatabase strMDBNamePath, , pwd
Else
.OpenCurrentDatabase strMDBNamePath
End If
Else
.DoCmd.Quit
End If
Kill strNewFile
End With
fCompactDatabase = True
Exit_Here:
On Error Resume Next
DoCmd.Close acForm, Forms(mconSTATUS_FORM)
Exit Function
Err_Handler:
fCompactDatabase = False
Select Case Err.Number
Case mconERR_INSTANCE_NOT_FOUND:
strMsg = "The Access instance containing the database " &
vbCrLf
strMsg = strMsg & pconQ & strMDBNamePath & pconQ & vbCrLf
strMsg = strMsg & "couldn't be located."
MsgBox strMsg, vbCritical + vbOKOnly, "Access instance not
found!"
Case mconERR_NO_COMMAND_LINE:
strMsg = "Invalid database name."
strMsg = strMsg & vbCrLf & vbCrLf & pconQ & pconQ & vbCrLf &
vbCrLf
strMsg = strMsg & "Compacter will terminate."
MsgBox strMsg, vbCritical + vbOKOnly, "Invalid database
name!"
Case mconERR_FILE_NOT_EXIST:
strMsg = "The database you specified" & vbCrLf
strMsg = strMsg & pconQ & strMDBNamePath & pconQ & vbCrLf
strMsg = strMsg & "doesn't exist." & vbCrLf & " Please check
the filename and try again!"
MsgBox strMsg, vbCritical + vbOKOnly, "File not found"
Case 429:
strMsg = "The Compacter utility couldn't locate Access
instance!"
MsgBox strMsg, vbExclamation + vbOKOnly, "Access instance not
found"
Case Else:
MsgBox "Error: " & Err.Number & ". " & Err.Description,
vbExclamation + vbOKOnly, _
"Unknown Error"
End Select
Resume Exit_Here
End Function
' *** Code End ***
-- Dev