Compact code not working-

S

Shane

Hi,
I saw the code postd that deleted tables if the admin
didnt open a form before a certain date.Ive been playing
around with it for about an hour and I cant seem to get
the Auto Compact to work. The code will run and quit, but
wont compact, Even if the compact on close option is
checked. Anyone know how to fix this?? Zach, did you
have the same problem???
Thanks

The code looks like this:

Private Sub Form_Open(cancel As Integer)
Dim db As DAO.Database, strUser As String
Dim dteDate As Date
Set db = CurrentDb
strUser = CurrentUser 'sees whose Logged On
If strUser <> "admin" Then 'if its NOT the admin
dteDate = DLookup("[Login]", "Log") 'look at the log
for the date
If DateDiff("d", dteDate, date) > 2 Then 'if that date is
older than 2 days, in this case
db.TableDefs.Delete "Table" 'delete table
db.QueryDefs.Delete "Query" 'delete query
DoCmd.DeleteObject acForm, "Form" 'delete form
DoCmd.DeleteObject acReport, "Report" 'delete report
DoCmd.DeleteObject acMacro, "Macro" 'delete macro
End If
ElseIf strUser = "admin" Then ' or if the user IS the
admin
db.Execute "UPDATE Log SET Log.[Login]= date();",
dbFailOnError 'update the field with todays date
Set db = Nothing
Application.SetOption "Auto Compact", True
Application.Quit
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top