I tried
Code:
# Public Sub DBbackup()
#
# Dim DestPath As String
# Dim SrcPath As String
# Dim fso As Object
#
# Set fso = CreateObject("Scripting.FileSystemObject")
# SrcPath = CurrentProject.FullName
# DestPath = CurrentProject.Path & "\BDbak" & Format(Now, "yymmddhhnnss") & ".mdb"
#
# fso.CopyFile SrcPath, DestPath
#
# Set fso = Nothing
# MsgBox "DB copied ", vbInformation, SBaviso
#
# End Sub
Code:
Private Sub Command150_Click()
Call BackupFrontEnd
CloseCurrentDatabase
End Sub
Public Function BackupFrontEnd()
Dim dbs
Dim tdfs
Dim fso
Dim strCurrentDB
Dim intExtPosition
Dim strExtension
Dim intExtlength
Dim strBackupPath
Dim sfld
Dim strDayPrefix
Dim strSaveName
Dim strProposedSaveName
Dim strTitle
Dim strPrompt
Dim SaveNo
Dim rst
On Error GoTo ErrorHandler
Set dbs = CurrentDb
Set tdfs = dbs.TableDefs
'Components of the FileSystemObject object library are used
'to work with files
Set fso = CreateObject("Scripting.FileSystemObject")
strCurrentDB = Application.CurrentProject.Name
Debug.Print "Current db: " & strCurrentDB
intExtPosition = InStr(strCurrentDB, ".")
strExtension = Mid(strCurrentDB, intExtPosition)
intExtlength = Len(strExtension)
'Create backup path string (Backups folder under database folder)
strBackupPath = Application.CurrentProject.Path & "\Backups\"
Debug.Print "Backup path: " & strBackupPath
'Check whether path is valid
On Error Resume Next
Set sfld = fso.GetFolder(strBackupPath)
If sfld Is Nothing Then
'Create folder
Set sfld = fso.CreateFolder(strBackupPath)
End If
On Error GoTo ErrorHandler
'Create proposed save name for backup
strDayPrefix = Format(Date, "d-mmm-yyyy")
strSaveName = Left(strCurrentDB, _
Len(strCurrentDB) - intExtlength) & " Copy " & SaveNo _
& ", " & strDayPrefix & strExtension
strProposedSaveName = strBackupPath & strSaveName
Debug.Print "Backup save name: " & strProposedSaveName
strTitle = "Database backup"
strPrompt = "Save database to " & strProposedSaveName & "?"
strSaveName = Nz(InputBox(prompt:=strPrompt, _
Title:=strTitle, Default:=strProposedSaveName))
'Deal with user canceling out of the InputBox
If strSaveName = "" Then
GoTo ErrorHandlerExit
End If
Set rst = dbs.OpenRecordset("zstblBackupInfo")
With rst
.AddNew
![SaveDate] = Format(Date, "d-mmm-yyyy")
![SaveNumber] = SaveNo
.Update
.Close
End With
fso.CopyFile Source:=CurrentDb.Name, _
destination:=strSaveName
Msgbox "A backup with todays date should have been saved in the backups subfolder"
ErrorHandlerExit:
Exit Function
ErrorHandler:
Msgbox "Error No: " & Err.Number & "; Description: " & _
Err.Description
Resume ErrorHandlerExit
End Function
And also this one....
Create a batch file (mycopy.bat):
copy c:\mydir\myfile.mdb d:\mybackupdir
Place a shortcut to it on your desktop.