i use this code to backup my db to the target folder in :Const kTargetDir =
make a button to run: BackupDB
Code:
Public Function BackupDb()
Dim vDir, f, vExt, vTargFile, vSrcDB
Dim vTargDir, vSuffx
Const kTargetDir = "\\server\BackupFolder\"
vSrcDB = CurrentDb.Name
If vSrcDB <> "" Then
getDirName vDB, vDir, f
vExt = Mid(f, InStrRev(f, "."))
vTargDir = kTargetDir
vSuffx = "_Backup" & format(Now,"yymmdd-hhnn") & vExt
vTargFile = vTargDir & f & vSuffx
Copy1File vSrcDB, vTargFile
End If
'FRONT END APP
MsgBox "Done", vbInformation, "Backup"
End Function
Public Function Copy1File(ByVal pvSrc, ByVal pvTarg) As Boolean
Dim fso
On Error GoTo errMake
Set fso = CreateObject("Scripting.FileSystemObject") '(reference: ms Scripting Runtime)
fso.CopyFile pvSrc, pvTarg
Copy1File = True
Set fso = Nothing
Exit Function
errMake:
'MsgBox Err.Description & vbCrLf & pvSrc, , "Copy1File(): " & Err
Set fso = Nothing
End Function
Public Sub getDirName(ByVal psFilePath, ByRef prvDir, Optional ByRef prvFile)
'psFilePath: full file path given
'prvDir : directory name output
'prvFile: filename only output
Dim i As Integer, sDir As String
i = InStrRev(psFilePath, "\") 'not available in '97
If i > 0 Then
prvDir = Left(psFilePath, i)
prvFile = Mid(psFilePath, i + 1)
''If Asc(Mid(prvFile, Len(prvFile), 1)) = 0 Then RemoveLastChr prvFile
End If
End Sub