Option Compare Database
Dim DBOld As String
Dim DBNew As String
Private Sub Form_Close()
On Error Resume Next
Dim OldFile As String, DBwithEXT, DBwithoutEXT, NewFile As String, CopyMyDB
OldFile = DBOld
DBwithEXT = Dir(OldFile)
DBwithoutEXT = left(DBwithEXT, Len(DBwithEXT) - 4)
Application.SetOption "Use Hijri Calendar", False
NewFile = DBNew & "\" & Format(Now, "yyyymmddhhnnss") & ".mdb"
CopyMyDB = "cmd.exe /C copy " & """" & OldFile & """" & " " & """" & NewFile & """"
Shell CopyMyDB, 0
Exit Sub
End Sub
Private Sub Form_Load()
DBOld = CurrentProject.Path & "\db2.mdb"
DBNew = CurrentProject.Path & "\tst\"
Call zerNc
End Sub
Sub delfiles()
Dim strFldr As String
Dim strFile As String
Dim FileToGet As String
strFldr = CurrentProject.Path & "\tst" ' modify folder to your own
strFile = Dir(strFldr & "\*.*") ' get list of files in folder
Do While Len(strFile) > 0
FileToGet = left(strFile, Len(strFile) - 4)
If FileToGet <= CStr(Format(Date - 3, "yyyymmdd")) Then
Kill strFldr & "\" & strFile
Else
End If
strFile = Dir
Loop
End Sub
Sub zerNc()
On Error Resume Next
Dim OldFile As String, DBwithEXT, DBwithoutEXT, NewFile As String, CopyMyDB
OldFile = DBOld
DBwithEXT = Dir(OldFile)
DBwithoutEXT = left(DBwithEXT, Len(DBwithEXT) - 4)
Application.SetOption "Use Hijri Calendar", False
NewFile = DBNew & "\" & Format(Now, "yyyymmddhhnnss") & ".mdb"
CopyMyDB = "cmd.exe /C copy " & """" & OldFile & """" & " " & """" & NewFile & """"
Shell CopyMyDB, 0
Exit Sub
Me.Requery
Call delfiles
End Sub
db.rar