By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,493 Members | 1,208 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,493 IT Pros & Developers. It's quick & easy.

Syntax for copying a file from one folder to another?

P: n/a
I am trying to write a simple on click procedure to copy a file who's name
is in a combo box on the form to another folder and overwrite the file by
the same name which is already there.

I have the following, but the CopyFile part does not work. It goes straight
through to the last message box and no file is copied.
Dim fso
Dim sfol As String, dfol As String
sfol = (CurrentProject.Path & "\TemplatesBackup")
dfol = CurrentProject.Path & "\Templates"
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
If Not fso.folderexists(sfol) Then
MsgBox sfol & " is not a valid folder/path.", vbInformation, "Invalid
Source"
ElseIf Not fso.folderexists(dfol) Then
MsgBox dfol & " is not a valid folder/path.", vbInformation, "Invalid
Destination"
Else
fso.CopyFile sfol & "\" & (Me![cboLetterName]) & ".dot", dfol & "\",
True
MsgBox "Your original selected template has been overwritten.",
vbInformation, "Success"

End If
If Err.Number = 53 Then
Exit Sub
End If
\
can anyone help me make this work, I have spent half the afternoon trying
brackets and quotes and all manner of small changes, but to no avail.

TIA
dixie
Mar 2 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Dixie wrote:
I am trying to write a simple on click procedure to copy a file who's name
is in a combo box on the form to another folder and overwrite the file by
the same name which is already there.

I have the following, but the CopyFile part does not work. It goes straight
through to the last message box and no file is copied.
Dim fso
Dim sfol As String, dfol As String
sfol = (CurrentProject.Path & "\TemplatesBackup")
dfol = CurrentProject.Path & "\Templates"
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
If Not fso.folderexists(sfol) Then
MsgBox sfol & " is not a valid folder/path.", vbInformation, "Invalid
Source"
ElseIf Not fso.folderexists(dfol) Then
MsgBox dfol & " is not a valid folder/path.", vbInformation, "Invalid
Destination"
Else
fso.CopyFile sfol & "\" & (Me![cboLetterName]) & ".dot", dfol & "\",
True
MsgBox "Your original selected template has been overwritten.",
vbInformation, "Success"

End If
If Err.Number = 53 Then
Exit Sub
End If
\
can anyone help me make this work, I have spent half the afternoon trying
brackets and quotes and all manner of small changes, but to no avail.

TIA
dixie

Look at the FileCopy Statement in help.
Mar 2 '07 #2

P: n/a
Probably forgot to wrap funny paths with double-quotes.
salad is right: why do this the hard way with FSO?
-Tom.

Mar 2 '07 #3

P: n/a
It's OK anyway, guys, thanks for pointing that out. My main problem was
that the file I was trying to replace was read-only and I had to add some
code to change it to vbNormal before I could overwrite it.

dixie

"Tom van Stiphout" <no*************@cox.netwrote in message
news:pb********************************@4ax.com...
Probably forgot to wrap funny paths with double-quotes.
salad is right: why do this the hard way with FSO?
-Tom.

Mar 5 '07 #4

P: n/a
"Dixie" <di***@dogmail.comwrote in
news:12*************@corp.supernews.com:
It's OK anyway, guys, thanks for pointing that out. My main problem
was that the file I was trying to replace was read-only and I had to
add some code to change it to vbNormal before I could overwrite it.

dixie
vbNormal will work on your computer?
Mar 5 '07 #5

P: n/a
Shouldn't it? AFAIK it does. I'll check later when I get home.

dixie

"lyle fairfield" <ly******@yahoo.cawrote in message
news:u0*************@read2.cgocable.net...
"Dixie" <di***@dogmail.comwrote in
news:12*************@corp.supernews.com:
>It's OK anyway, guys, thanks for pointing that out. My main problem
was that the file I was trying to replace was read-only and I had to
add some code to change it to vbNormal before I could overwrite it.

dixie

vbNormal will work on your computer?

Mar 7 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.