johnyjassi
Registered User.
- Local time
- Today, 08:23
- Joined
- Jun 6, 2008
- Messages
- 64
i am trying to run the code below from one of the experts here but it is giving me a debug error highlighting the dim fso as filesystemobject.
Any Help. I would appreciate your help.
Private Sub Form_Load()
On Error GoTo Err_Form_Load
Dim CompactedDB As String
Dim dbName, sBackupPath, sBackupFile As String
Dim fso As FileSystemObject
Dim DB As DAO.Database
Dim RS As DAO.Recordset
Dim JRO As JRO.JetEngine
Set JRO = New JRO.JetEngine
Set DB = CurrentDb()
Set RS = DB.OpenRecordset("DBNames")
RS.MoveFirst
Do Until RS.EOF
dbName = RS("DBFolder") & RS("DBName")
' Create a new name for the compacted database.
CompactedDB = Left(dbName, Len(dbName) - 4)
CompactedDB = CompactedDB & Format(Date, "MMDDYY") & ".mde"
JRO.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbName & ";User Id= realAdmin; Password =xxxxxx; Jet OLEDB:System Database = C:\DrawingRegister\DrawingsWorkGroup.mdw", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & CompactedDB & ""
'make backup of compacted file
sBackupPath = RS("DBBackupPath")
Set fso = New FileSystemObject
fso.CopyFile CompactedDB, sBackupPath & "BackupDrawingsDB" & ".mde", True 'copy file that has been compacted into backup folder
Set fso = Nothing
'delete old database
If Dir(dbName) <> "" Then Kill (dbName)
'rename temporary database to original name
Name CompactedDB As dbName
RS.MoveNext
Loop
' Close the form, and then close Microsoft Access
DoCmd.Close acForm, "CompactDB", acSaveYes
RS.Close
DoCmd.Quit acSaveYes
Exit_Form_Load:
Exit Sub
Err_Form_Load:
Debug.Print Err.Number & " - " & Err.Description
Resume Exit_Form_Load
End Sub
Any Help. I would appreciate your help.
Private Sub Form_Load()
On Error GoTo Err_Form_Load
Dim CompactedDB As String
Dim dbName, sBackupPath, sBackupFile As String
Dim fso As FileSystemObject
Dim DB As DAO.Database
Dim RS As DAO.Recordset
Dim JRO As JRO.JetEngine
Set JRO = New JRO.JetEngine
Set DB = CurrentDb()
Set RS = DB.OpenRecordset("DBNames")
RS.MoveFirst
Do Until RS.EOF
dbName = RS("DBFolder") & RS("DBName")
' Create a new name for the compacted database.
CompactedDB = Left(dbName, Len(dbName) - 4)
CompactedDB = CompactedDB & Format(Date, "MMDDYY") & ".mde"
JRO.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbName & ";User Id= realAdmin; Password =xxxxxx; Jet OLEDB:System Database = C:\DrawingRegister\DrawingsWorkGroup.mdw", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & CompactedDB & ""
'make backup of compacted file
sBackupPath = RS("DBBackupPath")
Set fso = New FileSystemObject
fso.CopyFile CompactedDB, sBackupPath & "BackupDrawingsDB" & ".mde", True 'copy file that has been compacted into backup folder
Set fso = Nothing
'delete old database
If Dir(dbName) <> "" Then Kill (dbName)
'rename temporary database to original name
Name CompactedDB As dbName
RS.MoveNext
Loop
' Close the form, and then close Microsoft Access
DoCmd.Close acForm, "CompactDB", acSaveYes
RS.Close
DoCmd.Quit acSaveYes
Exit_Form_Load:
Exit Sub
Err_Form_Load:
Debug.Print Err.Number & " - " & Err.Description
Resume Exit_Form_Load
End Sub