Z
ZACH
Hello,
I tried entering the code to set the log to delete info.
but Im not sure its working. I tried to change the Date to
TIME to run it at minutes instead of days to test. I think
I placed the TIME (and removed the "date") in two spots
and changed the "d" to "n" but when I run it, it skips the
delete. It just compacts and quits.
I also added the lines to delete queries and forms. but I
dont think its stated correctly. I dont know if it
matters but most of my tables have a relationship, and
when I attempted this in a macro i got the error that I
couldnt delete the table while the relationship existed.
Will this do the same??? I would like to delete the
queries and forms if at all possible.
Any Ideas on how to fix this and test?
thank you for your help.. I know im very close.
zach
Dim db As DAO.Database, strUser As String
Dim dteDate As Date
Set db = CurrentDb
strUser = CurrentUser
If strUser = "Admin" Then 'or whatever your login is
db.Execute "UPDATE Log SET Log.[Login]= "TIME"Date
();", dbFailOnError
End If
dteDate = DLookup("[Login]", "Log")
If DateDiff("n", dteDate, "TIME"Date) > 10 Then 'pick your
number of days here
db.Execute "Delete * From Activity Name"
db.QueryDefs.Delete Deleteqry
DoCmd.Delete, acform,"myform"
'Do this for each table you want to delete data from
End If
Set db = Nothing
Application.SetOption "Auto Compact", True
Application.Quit
I tried entering the code to set the log to delete info.
but Im not sure its working. I tried to change the Date to
TIME to run it at minutes instead of days to test. I think
I placed the TIME (and removed the "date") in two spots
and changed the "d" to "n" but when I run it, it skips the
delete. It just compacts and quits.
I also added the lines to delete queries and forms. but I
dont think its stated correctly. I dont know if it
matters but most of my tables have a relationship, and
when I attempted this in a macro i got the error that I
couldnt delete the table while the relationship existed.
Will this do the same??? I would like to delete the
queries and forms if at all possible.
Any Ideas on how to fix this and test?
thank you for your help.. I know im very close.
zach
Dim db As DAO.Database, strUser As String
Dim dteDate As Date
Set db = CurrentDb
strUser = CurrentUser
If strUser = "Admin" Then 'or whatever your login is
db.Execute "UPDATE Log SET Log.[Login]= "TIME"Date
();", dbFailOnError
End If
dteDate = DLookup("[Login]", "Log")
If DateDiff("n", dteDate, "TIME"Date) > 10 Then 'pick your
number of days here
db.Execute "Delete * From Activity Name"
db.QueryDefs.Delete Deleteqry
DoCmd.Delete, acform,"myform"
'Do this for each table you want to delete data from
End If
Set db = Nothing
Application.SetOption "Auto Compact", True
Application.Quit