fs.copyfile receiving error 52 - Bad file name or number

kwagner1

Active Member
Joined
Jun 10, 2003
Messages
445
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
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Why are you putting the string in double quotes?

I don't think you need to.

Try it without adding the double quotes.
 
Upvote 0
you are right! didnt need the quotes... thanks! i got sample code from someone... guess it was bogus..... but it now got me to where i wanted to be so... not so bad afterall....

thanks for your help!
 
Upvote 0

Forum statistics

Threads
1,221,905
Messages
6,162,770
Members
451,786
Latest member
CALEB23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top