Auto database backup/ copying a file in use

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • garfieldsevilla
    New Member
    • Feb 2010
    • 37

    Auto database backup/ copying a file in use

    I came up against the problem of how to backup an open database yesterday. I read various threads here and on other sites on how to do this but none gave a working solution. So here is mine- for comment. Any improvements would be welcome.

    In my case, the user is in a restricted interface and so cannot use the backup menu option. This has been tested on Access 2003:


    Code:
    Public Sub DBbackup()
    
    Dim DestPath As String
    Dim SrcPath As String
    Dim fso As Object
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    SrcPath = CurrentProject.Path & "\MyDB.mdb"
    DestPath = CurrentProject.Path & "\BDbak" & Format(Date, "yymmdd") & Format(Time(), "hhmmss") & ".mdb"
    
    fso.CopyFile SrcPath, DestPath
    
    Set fso = Nothing
    MsgBox "DB copied ", vbInformation, SBaviso
    
    End Sub
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32661

    #2
    Seems like pretty decent code to me. I would consider replacing line #8 with :
    Code:
    SrcPath = CurrentProject.FullName
    if it's the current database you want to copy. Alternately forget SrcPath altogether and refer to CurrentProject. FullName instead.

    You could also simplify line #9 as :
    Code:
    DestPath = CurrentProject.Path & "\BDbak" & Format(Now, "yymmddhhnnss") & ".mdb"

    Comment

    • garfieldsevilla
      New Member
      • Feb 2010
      • 37

      #3
      thank you. I didn't know about "CurrentProject .FullName" and Format with Now is much simpler. The Time part got hacked on late last night..

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32661

        #4
        Strangely, I'm looking for a thread I answered yesterday that really needed .Path, but I could only remember .FullName. Same problem in reverse :D

        As I said, the code was already pretty well there. Just a couple of minor tweaks really :)

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32661

          #5
          Though this isn't a question as such, and we do appreciate your posting it, this isn't an Insight either. With that in mind I'm moving it to Q&A. Still findable in a search, but not an Insight.

          Comment

          Working...