Hello, men
When you call this function with an event the time
Show me an error message
Code:
Private Sub Form_Timer()
Call Backup("c:\Test\202.mdb", "c:\Test\ds\az.mdb")
End Sub
Code:
Public Sub Backup(strSource As String, strTarget As String)
'creates a copy of whatever file you want to whatever folder you want, overwrites if already there
Dim fso As Object, fsoBackup As Object
Dim tempDate As Variant
Set fso = CreateObject("scripting.filesystemobject") 'set our filesystem object
If fso.FileExists(strTarget) Then 'if target does exist
Set fsoBackup = fso.getfile(strTarget) 'set target variable
tempDate = DateAdd("d", 1, fsoBackup.DateCreated) 'add whatever length of time to check (daily, hourly, etc.)
If Now() >= tempDate Then 'check if now is later than the date/time we want to copy it over next
fso.deletefile strTarget 'delete target to reset datecreated property
fso.copyfile strSource, strTarget 'copy source to target
End If
Else
fso.copyfile strSource, strTarget 'if target doesn't exist, immediately create backup
End If
End Sub