Place the following function in a Module. Then either call the Function from a Macro called AutoExec, which runs every time you start up the database, or place it in the open of a form that is opened once per session. Like a Log On screen, or a Switchboard that opens once.
The Function CompactCheck() needs a table I called "MDB Open Count". It has one field named "Open Count", which should be an Integer.
Hope this Helps!
Function CompactCheck()
Dim OpenCount As Integer
DoCmd.SetWarnings False
DoCmd.RunSQL "Update [MDB Open Count] Set [Open Count] = [Open Count] +1 ;"
OpenCount = DLookup("[Open Count]", "MDB Open Count"
If OpenCount > 2 Then
DoCmd.RunSQL "Update [MDB Open Count] Set [Open Count] = 1 ;"
Application.SetOption "Auto Compact", True
Else
Application.SetOption "Auto Compact", False
End If
DoCmd.SetWarnings True
End Function
Anthony J. DeSalvo
President - ScottTech Software
"Integrating Technology with Business"