Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / November 2006

Tip: Looking for answers? Try searching our database.

Deleting oldest file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
StuJol - 07 Nov 2006 23:24 GMT
i have an Access2003 database that when closes creates a backup of the
backend mdb file. the backup files filename contains the date of the backup
in its file name. for examples  MyDatabaseBackup 01 November 2006.bak

the folder where all these .bak files are stored has to potential to grow
out of control so im trying to limited the size of the backup folder to 10
backup files. ive created a function that counts the files. Im now tring to
create a function that when the count = 11 then delete the oldest file but i
dont know how to find the oldest file using code.

Can anybody assist please?
Van T. Dinh - 08 Nov 2006 11:55 GMT
Check Access VB Help on the FileDateTime() function.

Signature

HTH
Van T. Dinh
MVP (Access)

>i have an Access2003 database that when closes creates a backup of the
> backend mdb file. the backup files filename contains the date of the
[quoted text clipped - 10 lines]
>
> Can anybody assist please?
XP - 08 Nov 2006 14:24 GMT
StuJol,

Could you please post your VBA on how you run your back up? ---Or can
someone else please illustrate the VBA to do this, I am trying to do the same
thing...Thanks!

> i have an Access2003 database that when closes creates a backup of the
> backend mdb file. the backup files filename contains the date of the backup
[quoted text clipped - 7 lines]
>
> Can anybody assist please?
StuJol - 09 Nov 2006 14:51 GMT
XP

my Access2003 database is split into a FE and BE. when i close my
mainform/switchboard on the database i have an unbound form open. This form
acts as a message box telling me how many days it were since i last did a
backup and gives me the option to create a backup or cancel.

to backup your BE file simple use the following code

First i compact the BE before baking it up. The compacted BE is renamed as a
temp file as a result of the compact. then i rename the temp file back to the
original file name.

Function Compact()

   ' Compact the Back-End database to a temp file.
   DBEngine.CompactDatabase "C:\Program Files\Easara\Database\Easara
Database.mdb", "C:\Program Files\Easara\Database\Easara Database Temp.mdb"

   ' Delete the previous backup file if it exists.
    If Dir("C:\Program Files\Easara\Database\Easara Database.bak") <> "" Then
       Kill "C:\Program Files\Easara\Database\Easara Database.bak"
   End If

   ' Rename the current database as backup and rename the temp file to the
original file name.
   Name "C:\Program Files\Easara\Database\Easara Database.mdb" As
"C:\Program Files\Easara\Database\Easara Database.bak"
   Name "C:\Program Files\Easara\Database\Easara Database Temp.mdb" As
"C:\Program Files\Easara\Database\Easara Database.mdb"
   
   
End Function

to create a backup of the compacted BE use the following code

Dim SourceFile, DestinationFile

SourceFile = "C:\Program Files\Easara\Database\Easara Database.bak"    '
Define source file name.
DestinationFile = "C:\Program Files\Easara\Backups\Easara Database " &
Format(Date, "long date") & ".bak" ' Define target file name.

       FileCopy SourceFile, DestinationFile

Hpoe this helps you

> StuJol,
>
[quoted text clipped - 13 lines]
> >
> > Can anybody assist please?
Klatuu - 08 Nov 2006 16:17 GMT
Here is a function that will do what you want.  You only need to change the
names and path to suit your needs:

Public Sub DeleteOldestFile()
Dim dtmOldTime As Date
Dim strOldName As String
Dim lngCtr As Long

   dtmOldTime = Now()
   With Application.FileSearch
       .NewSearch
       .LookIn = "C:\documents and settings\Bozo\my documents"
       .filename = "*.bak"
       .Execute
       If .FoundFiles.Count >= 11 Then
           For lngCtr = 1 To .FoundFiles.Count
               If FileDateTime(.FoundFiles(lngCtr)) < dtmOldTime Then
                   dtmOldTime = FileDateTime(.FoundFiles(lngCtr))
                   strOldName = .FoundFiles(lngCtr)
               End If
           Next lngCtr
           If MsgBox("old file " & strOldName & vbNewLine & "old date " _
                   & dtmOldTime, vbQuestion + vbYesNo, "Delete This File") _
                   = vbYes Then
               Kill strOldName
           End If
       End If
   End With
   
End Sub

> i have an Access2003 database that when closes creates a backup of the
> backend mdb file. the backup files filename contains the date of the backup
[quoted text clipped - 7 lines]
>
> Can anybody assist please?
StuJol - 09 Nov 2006 14:53 GMT
many thanks Klatuu. Worked great and now i also know that their is a
filesearch function available if i ever need it again.

Many Thanks

> Here is a function that will do what you want.  You only need to change the
> names and path to suit your needs:
[quoted text clipped - 38 lines]
> >
> > Can anybody assist please?
Klatuu - 09 Nov 2006 15:13 GMT
Glad to help.  filesearch is not a function, it is an object.

> many thanks Klatuu. Worked great and now i also know that their is a
> filesearch function available if i ever need it again.
[quoted text clipped - 43 lines]
> > >
> > > Can anybody assist please?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.