P
Pete
I am using the following code to compact a backend database. However,
I am getting the 3356 error and can not thnk of what to try next.
The base program requires a logon process and then display a form with
with data from the backend. The backup command is issued through a
macro which results in the tables being dumped to an XLS file. Once
the tables have been dumped, I execute the code. I am missing
somthing. Any ideas would be helpful. THANKS in advance.
Sub CompactDB()
Dim conFilePath
Dim intX As Integer, _
intCOUNT As Integer
Dim rs As Recordset
Dim QD As QueryDef
On Error GoTo CompactDB_Err
' Make sure all forms are closed
intCOUNT = Forms.Count - 1
For intX = intCOUNT to 0 step -1
If Forms(intX).Name <> "frmBackup" Then
DoCmd.Close acForm, Forms(intX).Name
End If
Next intX
' Make sure all recordsets are closed
For Each rs In CurrentDb.Recordsets
rs.Close
Next rs
' make sure all querys are closed
For Each QD In CurrentDb.QueryDefs
QD.Close
Next QD
conFilePath = CurrentDb.TableDefs("Roster").Connect
conFilePath = Mid$(conFilePath, InStr(1, conFilePath, "DATABASE=")
+ 9)
conFilePath = Mid$(conFilePath, 1, InStr(1, conFilePath,
"ScoutRoster_Tables.mdb") - 1)
' Compact the database to a temp file.
DBEngine.CompactDatabase conFilePath & "DBASE1_Tables.mdb", _
conFilePath & "DBase1_Temp.mdb"
' Delete the previous backup file if it exists.
If Dir(conFilePath & "DBase1_Tables.bak") <> "" Then
Kill conFilePath & "DBase1_Tables.bak"
End If
' Rename the current database as backup and rename the temp file to
' the original file name.
Name conFilePath & "DBase1_Tables.mdb" As conFilePath &
"DBase1_Tables.bak"
Name conFilePath & "DBASE1_Temp.mdb" As conFilePath &
"DBase1_Tables.mdb"
Exit_CompactDB:
Exit Sub
CompactDB_Err:
MsgBox "Routine=" & Me.Name & ": CompactDB" & vbCrLf & _
"Error=" & Err.Number & vbCrLf & _
"Description=" & Err.Description
I am getting the 3356 error and can not thnk of what to try next.
The base program requires a logon process and then display a form with
with data from the backend. The backup command is issued through a
macro which results in the tables being dumped to an XLS file. Once
the tables have been dumped, I execute the code. I am missing
somthing. Any ideas would be helpful. THANKS in advance.
Sub CompactDB()
Dim conFilePath
Dim intX As Integer, _
intCOUNT As Integer
Dim rs As Recordset
Dim QD As QueryDef
On Error GoTo CompactDB_Err
' Make sure all forms are closed
intCOUNT = Forms.Count - 1
For intX = intCOUNT to 0 step -1
If Forms(intX).Name <> "frmBackup" Then
DoCmd.Close acForm, Forms(intX).Name
End If
Next intX
' Make sure all recordsets are closed
For Each rs In CurrentDb.Recordsets
rs.Close
Next rs
' make sure all querys are closed
For Each QD In CurrentDb.QueryDefs
QD.Close
Next QD
conFilePath = CurrentDb.TableDefs("Roster").Connect
conFilePath = Mid$(conFilePath, InStr(1, conFilePath, "DATABASE=")
+ 9)
conFilePath = Mid$(conFilePath, 1, InStr(1, conFilePath,
"ScoutRoster_Tables.mdb") - 1)
' Compact the database to a temp file.
DBEngine.CompactDatabase conFilePath & "DBASE1_Tables.mdb", _
conFilePath & "DBase1_Temp.mdb"
' Delete the previous backup file if it exists.
If Dir(conFilePath & "DBase1_Tables.bak") <> "" Then
Kill conFilePath & "DBase1_Tables.bak"
End If
' Rename the current database as backup and rename the temp file to
' the original file name.
Name conFilePath & "DBase1_Tables.mdb" As conFilePath &
"DBase1_Tables.bak"
Name conFilePath & "DBASE1_Temp.mdb" As conFilePath &
"DBase1_Tables.mdb"
Exit_CompactDB:
Exit Sub
CompactDB_Err:
MsgBox "Routine=" & Me.Name & ": CompactDB" & vbCrLf & _
"Error=" & Err.Number & vbCrLf & _
"Description=" & Err.Description