Article ID: 158937
Article Last Modified on 1/19/2007
Table: DBNames
----------------------------------------------------
Field Name: DBID
Data Type: AutoNumber (or Counter in version 2.0)
Field Name: DBFolder
Data Type: Text
Field Size: 255
Field Name: DBName
Data Type: Text
Field Size 255
Table Properties: DBNames
-------------------------
PrimaryKey: DBID
Caption: Compact Databases<BR/>
Default View: Single Form<BR/>
Scrollbars: Neither<BR/>
RecordSelectors: No<BR/>
NavigationButtons: No<BR/>
OnTimer: [Event Procedure]<BR/>
TimerInterval: 60000
Private Sub Form_Timer()
'==================================================================
'The Timer event runs this code every minute. It compares your
'system time with the StartTime variable. When they match, it
'starts to compact all databases in the DBNames table.
'==================================================================
Dim StartTime As String
' Set this variable for the time you want compacting to start.
StartTime = "12:00 AM"
' If StartTime is now, open the DBNames table and start compacting
If Format(Now(), "medium time") = Format(StartTime, _
"medium time") Then
Dim RS As Recordset, DB As DATABASE
Dim NewDBName As String, DBName As String
Set DB = CurrentDb()
Set RS = DB.OpenRecordset("DBNames")
On Error Resume Next
RS.MoveFirst
Do Until RS.EOF
DBName = RS("DBFolder") & "\" & RS("DBName")
' Create a new name for the compacted database.
' This example uses the old name plus the current date.
NewDbName = Left(DbName, Len(DbName) - 4)
NewDbName = NewDbName & " " & Format(Date, "MMDDYY") & ".mdb"
DBEngine.CompactDatabase DBName, NewDBName
RS.MoveNext
Loop
' Close the form, and then close Microsoft Access
DoCmd.Close acForm, "CompactDB", acSaveYes
RS.Close
DoCmd.Quit acSaveYes
End If
End Sub
Private Sub Form_Timer()
'==================================================================
'The Timer event runs this code every minute. It compares your
'system time with the StartTime variable. When they match, it
'begins to compact all databases in the DBNames table.
'==================================================================
Dim StartTime As String
' Set this variable for the time you want compacting to begin.
StartTime = "12:00 AM"
' If StartTime is now, open the DBNames table and start compacting.
If Format(Now(), "medium time") = Format(StartTime, _
"medium time") Then
Dim RS As Recordset, DB As DATABASE
Dim NewDBName As String, DBName As String
Set DB = CurrentDb()
Set RS = DB.OpenRecordset("DBNames")
On Error Resume Next
RS.MoveFirst
Do Until RS.EOF
DBName = RS("DBFolder") & "\" & RS("DBName")
' Create a new name for the compacted database.
' This example uses the DBID plus the current date, which
' falls in DOS 8.3 file name limits for DBID = 1 to 99.
NewDBName = RS("DBFolder") & "\" & RS("DBID") & Format(Date, _
"MMDDYY") & ".mdb"
DBEngine.CompactDatabase DBName, NewDBName
RS.MoveNext
Loop
' Close the form, and then close Microsoft Access.
DoCmd Close a_Form, "CompactDB"
DoCmd Quit a_Save
End If
End Sub
Action
--------
OpenForm
Action Arguments
--------------------
Form Name: CompactDB
View: Form
Data Mode: Read Only
Window Mode: Normal
DBID DBFolder DBName
---------------------------------------------------
1 C:\MSOffice\Access\Samples Northwind.mdb
2 \\Servername\Access\Sampapps Nwind.mdb
<B>c: cd\program files\microsoft office\office Msaccess.exe c:\Northwind.mdb /compact</B>The path to the Access executable program is c:\program files\microsoft office\office. Msaccess.exe may be in a different location on your computer. If so, you can use the Find command on the Start menu to locate Msaccess.exe, and then determine the correct path.
<B>c:
cd\program files\microsoft office\office
Msaccess.exe C:\Northwind.mdb /compact</B>
The path to the Access executable program is c:\program files\microsoft office\office. Msaccess.exe may be in a different location on your computer. If so, you can use the Find command on the Start menu to locate Msaccess.exe and determine the correct path.231478 ACC97: How to Start Access by Using the Windows NT Schedule Service
105128 ACC: How to Use Command-Line Switches in Microsoft Access
Additional query words: inf
Keywords: kbhowto kbprogramming KB158937