using filecopy or name statements

  • Thread starter Thread starter Tammy
  • Start date Start date
T

Tammy

This is really just a VBA question, I guess. I am trying
to use the 'filecopy' or 'name' statement so that when
the user clicks on a button on the form he/she moves the
file from a 'drafts' folder to a 'saved' folder. I keep
getting error messages that the file or path is not
found. However, there was a search done both by me and
prviously in the program (filesearch) which confirms the
file exists. Apparently there is a problem copying the
file to the new folder?! The folder does exist, but the
file will normally (not always) be a new file.

Here is the current code: (I have used the 'kill'
command with the 'filecopy' as I actually want the file
moved and to not exist anymore in the 'drafts' folder!
They are commented out as I was testing the 'name'
statement!)

THANKS!

'move file from "drafts" to "SavedSOPs": uses
filecopy to copy the file & then 'kill'
'statement to delete the draft file
strSPath = "C:\Documents and Settings\Owner\My
Documents\SOPs\drafts\"
strDPath = "C:\Documents and Settings\Owner\My
Documents\SOPs\SavedSOPs\"
strFile = Me![txtSOP] & ".doc"
strSFile = strSPath & strFile
strDFile = strDPath & strFile
Name strSFile As strDFile
'FileCopy strSPath, strDPath
'Kill strSPath
 
Tammy,

As far as I understand what you are doing, the Name...As... statement
should be sufficient to do what you want. You can just drop the
FileCopy and Kill lines from your code. In any case, it looks like
there are errors with these 2 lines, becasue shouldn't they refer to
strSFile instead of strSPath?

- Steve Schapel, Microsoft Access MVP
 
Without actually trying it to confirm the problem, I believe that your
problem is that there are spaces in the paths and/or file names and so the
whole thing needs to be enclosed in quotes.

Try adjusting these 2 lines:
strSFile = """" & strSPath & strFile & """"
strDFile = """" & strDPath & strFile & """"

That's 4 quotes in each set. The outer 2 in each set are just normal quotes
and the inner 2 cause a quote to be added to the resulting string.
 
Wayne Morgan said:
Without actually trying it to confirm the problem, I believe that your
problem is that there are spaces in the paths and/or file names and
so the whole thing needs to be enclosed in quotes.

Try adjusting these 2 lines:
strSFile = """" & strSPath & strFile & """"
strDFile = """" & strDPath & strFile & """"

That's 4 quotes in each set. The outer 2 in each set are just normal
quotes and the inner 2 cause a quote to be added to the resulting
string.

I don't think that's it, Wayne. Adding the extra quotes shouldn't be
necessary. For example,

strOldName = "C:\Documents and Settings\Dirk\My Documents\Referee
Schedule.txt"
strNewName = "C:\Documents and Settings\Dirk\My Documents\Referee
Schedule 2003.txt"
Name strOldName As strNewName

works just fine for me.
 
Thanks Dirk,

I know I ran into that somewhere. It was probably a Shell statement instead.
 
Wayne Morgan said:
Thanks Dirk,

I know I ran into that somewhere. It was probably a Shell statement
instead.

It definitely does make a difference in the Shell statement, at least
under some operating systems. ISTR that there's a difference from OS
version to OS version.
 
In addition to what the others have said:

Add these:
debug.print ">"; strSFile; "|"; dir$(strSFile); "<"
debug.print ">"; strSDile; "|"; dir$(strDFile); "<"

before this:
Name strSFile As strDFile

Then you can verify that the two variables contain what you think they do,
and you will also see which (if either) of the source & destinations already
exist. (Dir$("x") returns null if "x" doesn't exist.) That should find the
problem for you.

And a tip: since both of the folders have the same root, this might be
useful:

const ROOT_PATH as string = "C:\Documents and Settings\Owner\My
Documents\SOPs\"

Then you would just need:
strSPath = ROOT_PATH & "drafts\"
strDPath = ROOT_PATH & "SavedSOPs\"

which avoids unnecessary duplication.

HTH,
TC
 
Back
Top