I am very grateful to ghudson and jon jamaco for the two examples of VBA that I have used in my 2002-2003 Format Database.
I needed like many others in this forum to backup my database but I was a little unsure how to use ghudson's code correctly. Jon jamaco's code worked a treat but I did not want to save my backup copy in the root directory.
I have attempted to consolidate the two sets of code to save a copy in another folder but so far my new sub has been unsuccessful in completing the task.
I have attached my edited code below:
The two unedited samples are attached below:
Any assistance gratefully received.
I needed like many others in this forum to backup my database but I was a little unsure how to use ghudson's code correctly. Jon jamaco's code worked a treat but I did not want to save my backup copy in the root directory.
I have attempted to consolidate the two sets of code to save a copy in another folder but so far my new sub has been unsuccessful in completing the task.
I have attached my edited code below:
Code:
Private Sub Command325_Click()
Dim bckup As FileSystemObject
On Error GoTo Unsuccessful
Dim sSourcePath As String
Dim sSourceFile As String
Dim sBackupPath As String
Dim sBackupFile As String
sSourcePath = "I:\EurobipDBs\"
sSourceFile = "euroBIPFromNov05_2008-04-22_(1).mdb"
sBackupPath = "I:\EurobipDBs\Backups"
sBackupFile = "EurobipBackupDB_" & Format(Date, "mmddyyyy") & "_" & Format(Time, "hhmmss") & ".mdb"
Set bckup = New FileSystemObject
bckup.CopyFile sSourcePath & sSourceFile, sBackupPath & sBackupFile, True
Set bckup = Nothing
Beep
MsgBox "Backup was successful and saved @ " & Chr(13) & Chr(13) & sSourcePath & sSourceFile, sBackupPath & sBackupFile & Chr(13) & Chr(13) & "The backup file name is " & Chr(13) & Chr(13) & sBackupFile, vbInformation, "Backup Completed"
End
Unsuccessful:
MsgBox "Backup unsuccessful. Check:" & Chr(13) & Chr(13) & "- The disk you are saving to is not full" & Chr(13) & Chr(13) & "AND" & Chr(13) & Chr(13) & "- That a 'backups' folder has been created in the directory of the active database", vbExclamation, "Backup Unsuccessful"
The two unedited samples are attached below:
Code:
Public Function BackupCopy()
'This function will allow you to copy a db that is open,
'You must set a reference to the 'Microsoft Scripting Runtime' for the CopyFile piece to work!
Dim fso As FileSystemObject
Dim sSourcePath As String
Dim sSourceFile As String
Dim sBackupPath As String
Dim sBackupFile As String
sSourcePath = "F:\EurobipDatabaseBackups\"
sSourceFile = "euroBIPFromNov05_2008-04-22_(1).mdb"
sBackupPath = "F:\EurobipDatabaseBackups\"
sBackupFile = "EurobipBackupDB_" & Format(Date, "mmddyyyy") & "_" & Format(Time, "hhmmss") & ".mdb"
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile sSourcePath & sSourceFile, sBackupPath & sBackupFile, True
Set fso = Nothing
Beep
MsgBox "Backup was successful and saved @ " & Chr(13) & Chr(13) & sBackupPath & Chr(13) & Chr(13) & "The backup file name is " & Chr(13) & Chr(13) & sBackupFile, vbInformation, "Backup Completed"
End Function
Code:
Private Sub Command325_Click()
Dim bckup As FileSystemObject
On Error GoTo Unsuccessful
Dim strBckupName As String
strBckupName = "BackupDB - " & Format(Date, "mm.dd.yyyy") & " - " & Format(Time, "hhmmss") & ".mdb"
Set bckup = New FileSystemObject
bckup.CopyFile Application.CurrentProject.FullName, Application.CurrentProject.Path & "\Backups\" & strBckupName, True
Set bckup = Nothing
Beep
MsgBox "Backup was successful and saved @ " & Chr(13) & Chr(13) & Application.CurrentProject.Path & "\Backups" & Chr(13) & Chr(13) & "The backup file name is " & Chr(13) & Chr(13) & strBckupName, vbInformation, "Backup Completed"
End
Unsuccessful:
MsgBox "Backup unsuccessful. Check:" & Chr(13) & Chr(13) & "- The disk you are saving to is not full" & Chr(13) & Chr(13) & "AND" & Chr(13) & Chr(13) & "- That a 'backups' folder has been created in the directory of the active database", vbExclamation, "Backup Unsuccessful"
End Sub
Any assistance gratefully received.