I have a tConfig table so the Admin user can enter the target folder saved to backup to.
on the fAdmin form (tConfig table) , there is a button to click to copy:
I have a table that is always in the backend, (tAlpha) for the getBeDbFromLink()
if it has a string in the .CONNECT property, then the db is split,
if not, it is a single unsplit Db.
Code:
sub btnBackup_Click()
vSrcDb = getBeDbFromLink()
If vSrcDb = "" Then vSrcDb = CurrentDb.Name
'get the extension
i = InStrRev(vSrcDb, "\")
If i = 0 Then
msgbox "Error in filename backup"
exit sub
else
f = Mid(vSrcDb, i + 1)
endif
vExt = Mid(f, InStrRev(f, "."))
vTargDir = me.txtTargetFolder 'get target folder from textbox
vSuffx = "_Backup" & Format(Now,"yymmdd-hhnn") & vExt
vTargDb = vTargDir & f & vSuffx
Copy1File vSrcDb, vTargDB
msgbox "Backup Done"
end sub
'get the BackEnd database name from a linked table
Public Function getBeDbFromLink()
Dim vLink
vLink = CurrentDb.TableDefs("tAlpha").Connect
If vLink = "" Then
getBeDbFromLink = CurrentDb.Name
Else
getBeDbFromLink = Mid(vLink, 11)
End If
End Function
'copy file
Public Sub Copy1File(ByVal pvSrc, ByVal pvTarg)
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFile pvSrc, pvTarg
Set FSO = Nothing
End Sub