Schedule Compact

RussG

Registered User.
Local time
Today, 23:12
Joined
Feb 10, 2001
Messages
178
I am (a complete beginner with VB) trying to schedule a shared DB to compact at a chosen time. I have followed the MS knowledge base instructions for Access 2000. The Timer event tries to run but I get an error message, here is the code and error:

Private Sub Form_Timer()
Dim StartTime As String
' Set this variable for the time you want compacting to begin.
StartTime = "19:15 PM"
' If StartTime is now, open the DBNames table and start compacting
If Format(Now(), "medium time") = Format(StartTime, "medium time") Then
Dim RS As DAO.Recordset, DB As DAO.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

ERROR MESSAGE ( with above BOLD code highlighted)
Compile error
User defned type not defined.

Would greatly appreciate any help with this.
Thanks
Russ
 
You need to set a Reference to the DAO 3.5 (or above) library:
Open a Module->Tools->References->Microsoft DAO 3.x Library
 
On the money, thanks.
Russ
 
Question..

I copied and pasted the code in my main form under Timer and changed the time to a few minutes ahead so that I can see what happens. I also checked and DAO 3.5 was already checked off.

I was on the look out but didn't see any changes occur. Closed the database and looked at the file size but it didn't change.

Can you tell me to look out for and how to setup the "situation" for it to work (i.e. leave the database open, leave the main form open etc)

Thanks!
 

Users who are viewing this thread

Back
Top Bottom