PC Review


Reply
Thread Tools Rate Thread

CompactDataBase runtime 3356

 
 
Pete
Guest
Posts: n/a
 
      29th Jan 2006
I am trying to get the following code to compact a linked mdb.
However, I get a runtime error on the line
"Application.DBEngine.CompactDatabase mdbPATH, tempPATH". I added to
the line "CurrentDb.Close"

Is there anyway to compact a MDB by closing the current link mdb,
compacting, and then reopen it?

Public Function BackupDataBase()

Dim tdf As TableDef
Dim fs As Object
Dim mdbPATH As String, _
backupPATH As String, _
tempPATH As String, _
strSQL As String
Dim intIndex As Integer
Dim col As Access.Forms

MsgBox "Closing any Open forms to allow Backup to complete."
Set col = Forms
For intIndex = col.Count - 1 To 0 Step -1
DoCmd.Close acForm, col(intIndex).Name, acSaveNo
Next intIndex

' get the path and name of the current linked MDB
CurrentDb.TableDefs.Refresh
For Each tdf In CurrentDb.TableDefs
With tdf
If Len(.Connect) > 0 Then
If Left$(.Connect, 4) <> "ODBC" Then
mdbPATH = .Connect
mdbPATH = Mid$(mdbPATH, InStr(1, mdbPATH, "=") + 1)
Exit For
End If
End If
End With
Next
Set tdf = Nothing

' build the backup path name and make sure the directory is present
backupPATH = CurrentProject.Path & "\BackupData\"
If Len(Dir(backupPATH, vbDirectory)) < 1 Then
MkDir (backupPATH)
End If
' Add thre MDB name to the backup path
backupPATH = backupPATH & Mid$(mdbPATH, InStrRev(mdbPATH, "\") + 1)
' Add the date and time information to the backup ame
backupPATH = backupPATH & "." & Year(Date) & _
Format(Month(Date), "00") & _
Format(Day(Date), "00")

' Make a copy of the current MDB
Set fs = CreateObject("Scripting.FileSystemObject")
' FileCopy mdbPATH, backupPATH
fs.CopyFile mdbPATH, backupPATH, True

' Compact the current MDB into the temp mdb file
' (If there is a problem, then the original mdb is preserved)
tempPATH = "c:\tmpCompact.mdb"
CurrentDb.Close
Application.DBEngine.CompactDatabase mdbPATH, tempPATH

If Err.Number > 0 Then
' There was an error. Inform the user and halt execution
MsgBox "The following error was encountered while compacting
database:" & _
vbCrLf & vbCrLf & _
Err.Description
Else

' There are no errors so, replace the current and backup MDBs
' with the new compacted MDB
FileCopy tempPATH, mdbPATH
FileCopy tempPATH, backupPATH

' Kill the tempfile that was used
Kill tempPATH

strSQL = "UPDATE Text_Data " & _
"SET [option]=""" & Date & """ " & _
"WHERE [FieldType]=""SysOption"" AND
[Value]=""Backup"""

' Debug.Print strSQL
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "Database backup has completed sucessfully.", vbOKOnly,
"Database Backup"

End If

End Function

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why do I get 3356:Reserved Error? Stapes Microsoft Access 1 18th Mar 2008 04:56 PM
Error 3356 - When trying to convert Lisa - NH Microsoft Access 2 12th Mar 2008 03:44 PM
Error 3356 =?Utf-8?B?TCBFb3J5?= Microsoft Access Security 5 4th Jun 2007 11:41 AM
CompactDataBase runtime 3356 HELP NEEDED Pete Microsoft Access 9 16th Mar 2006 07:26 AM
error 3356 =?Utf-8?B?R2VldGhhIFByaXlh?= Microsoft Access 0 9th Dec 2004 06:51 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:07 AM.