G
Guest
Hello,
I done this before but for some reason I can't seem to find my mistake tonight. I would like to go through each record in the table and perform a file copy. My code look something like:
Dim db As Database
Dim rst As Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordset("Backup Information")
With rst
If .RecordCount > 0 Then
..MoveFirst
Do
Dim SourceFile, SourceFileName, SourceFilePath As String
Dim DestinationFile As String, DestinationFilePath As String, DestinationFileName As String, MDestinationFile As String, MDestinationFilePath As String
'*****Routine to retrieve the name of the SourceFileFile name function
SourceFile = [File to be Backed Up] ' Define the file to be Backed up
SourceFilePath = Left(SourceFile, InStrRev(SourceFile, "\"))
SourceFileName = Mid(SourceFile, InStrRev(SourceFile, "\") + 1, InStrRev(SourceFile, ".") - InStrRev(SourceFile, "\") - 1)
SourceFileType = Mid(SourceFile, InStrRev(SourceFile, ".") + 1)
'*****Rework destination file to be based on SourceFile
DestinationFilePath = [Backup Location] ' Location where backup is to be stored
If IsNull([Backup File Name]) Then
DestinationFileName = SourceFileName & "-" & Format(Date, "dd_mmm_yyyy") ' Filename be to attributed to the backup file
Else
DestinationFileName = [Backup File Name]
End If
DestinationFile = DestinationFilePath & DestinationFileName & "." & SourceFileType ' Identifies that backup file name & location with a date code
..MoveNext
FileCopy SourceFile, DestinationFile
Loop Until .EOF
End If
..Close
End With
It seems to continually loop on the first record. Can't someone please point out my mistake!
Thank you
Daniel
I done this before but for some reason I can't seem to find my mistake tonight. I would like to go through each record in the table and perform a file copy. My code look something like:
Dim db As Database
Dim rst As Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordset("Backup Information")
With rst
If .RecordCount > 0 Then
..MoveFirst
Do
Dim SourceFile, SourceFileName, SourceFilePath As String
Dim DestinationFile As String, DestinationFilePath As String, DestinationFileName As String, MDestinationFile As String, MDestinationFilePath As String
'*****Routine to retrieve the name of the SourceFileFile name function
SourceFile = [File to be Backed Up] ' Define the file to be Backed up
SourceFilePath = Left(SourceFile, InStrRev(SourceFile, "\"))
SourceFileName = Mid(SourceFile, InStrRev(SourceFile, "\") + 1, InStrRev(SourceFile, ".") - InStrRev(SourceFile, "\") - 1)
SourceFileType = Mid(SourceFile, InStrRev(SourceFile, ".") + 1)
'*****Rework destination file to be based on SourceFile
DestinationFilePath = [Backup Location] ' Location where backup is to be stored
If IsNull([Backup File Name]) Then
DestinationFileName = SourceFileName & "-" & Format(Date, "dd_mmm_yyyy") ' Filename be to attributed to the backup file
Else
DestinationFileName = [Backup File Name]
End If
DestinationFile = DestinationFilePath & DestinationFileName & "." & SourceFileType ' Identifies that backup file name & location with a date code
..MoveNext
FileCopy SourceFile, DestinationFile
Loop Until .EOF
End If
..Close
End With
It seems to continually loop on the first record. Can't someone please point out my mistake!
Thank you
Daniel