Greetings,
i'm getting a RunTime error 52 when trying to execute a backup of my .mdb file with the following code. Code works fine when i hard code the path into the "COPYFILE" command.... any ideas why it wont work as coded below?? thanks!
Sub testbackup()
On Error GoTo ErrorHandler
Dim strCurrentDB, strCurrentDBNoExt As String
Dim strBackupPath As String
Dim strDay, strTime, strSaveName As String
Dim fs As Object
strCurrentDB = Application.CurrentProject.Name ' get ".mdb" name
strCurrentDBNoExt = Mid(strCurrentDB, 1, Len(strCurrentDB) - 4) 'Trim off extension
strBackupPath = Application.CurrentProject.Path & "\Backups\" 'set the Backup pathname
strCurrentDB = Application.CurrentProject.Path & "\" & strCurrentDB
strCurrentDB = """" & strCurrentDB & """" ' put the string in double quotes
strDay = Format(Date, "yyyymmdd") ' get the day value
strTime = Format(Time, "hhmmss") ' get the time value
strSaveName = strCurrentDBNoExt & " " & strDay & strTime & ".mdb"
strSaveName = """" & strBackupPath & strSaveName & """" ' put the string in double quotes
MsgBox strCurrentDB & ", " & strSaveName ' display what copyfile cmd will look like
Set fs = CreateObject("Scripting.FileSystemObject")
fs.copyfile strCurrentDB, strSaveName ' copy the file (**** WORKS FINE IF I HARD CODE PATH NAME.. WHY???)
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox "Error No: " & Err.Number & "; Description: " & _
Err.Description
Resume ErrorHandlerExit
End Sub
i'm getting a RunTime error 52 when trying to execute a backup of my .mdb file with the following code. Code works fine when i hard code the path into the "COPYFILE" command.... any ideas why it wont work as coded below?? thanks!
Sub testbackup()
On Error GoTo ErrorHandler
Dim strCurrentDB, strCurrentDBNoExt As String
Dim strBackupPath As String
Dim strDay, strTime, strSaveName As String
Dim fs As Object
strCurrentDB = Application.CurrentProject.Name ' get ".mdb" name
strCurrentDBNoExt = Mid(strCurrentDB, 1, Len(strCurrentDB) - 4) 'Trim off extension
strBackupPath = Application.CurrentProject.Path & "\Backups\" 'set the Backup pathname
strCurrentDB = Application.CurrentProject.Path & "\" & strCurrentDB
strCurrentDB = """" & strCurrentDB & """" ' put the string in double quotes
strDay = Format(Date, "yyyymmdd") ' get the day value
strTime = Format(Time, "hhmmss") ' get the time value
strSaveName = strCurrentDBNoExt & " " & strDay & strTime & ".mdb"
strSaveName = """" & strBackupPath & strSaveName & """" ' put the string in double quotes
MsgBox strCurrentDB & ", " & strSaveName ' display what copyfile cmd will look like
Set fs = CreateObject("Scripting.FileSystemObject")
fs.copyfile strCurrentDB, strSaveName ' copy the file (**** WORKS FINE IF I HARD CODE PATH NAME.. WHY???)
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox "Error No: " & Err.Number & "; Description: " & _
Err.Description
Resume ErrorHandlerExit
End Sub