FileCopy Function (1 Viewer)

Status
Not open for further replies.

ipr1

Registered User.
Local time
Today, 11:25
Joined
Jun 13, 2003
Messages
31
Hi - I am trying to copy one file (the source) to another location (the destination) and. ideally, I would like to add a date to the file as it is copied.

This is the code I am using:

Function Nightly()

Dim CurrentDate As String
CurrentDate = Date
CurrentDate = Format(CurrentDate, "MMDDYY")

FileCopy "\\nel\mfsc-dsndm-d\Nightly.rpt", "\\netapp3\ds-mfsas-d\Backup Secure\Nightly_CurrentDate.rpt"

End Function

The error message I am receiving is "RunTime Error 76", "Path not found". I assume that my problem lies with the fact that both the source and destinations need to be string functions and in that regard I have tried concatenations etc. (e.g. "\\nel\mfsc-dsndm-d\" & "Nightly" & ".rpt" and "netapp3\ds-mfsas-d\BackupSecure\" & "Nightly" & "__CurrentDate"& ".rpt" but NOTHING seems to work.

Any suggestions? Thanks in advance for your help.
 

modest

Registered User.
Local time
Today, 06:25
Joined
Jan 4, 2005
Messages
1,220
Code:
Dim fso As New FileSystemObject
fso.CopyFile "file name", "to", Overwrite (true/false)

Note you need to include a reference to the Windows Script Host
 

Shadez

Registered User.
Local time
Today, 11:25
Joined
Jan 20, 2003
Messages
192
modest said:
Code:
Dim fso As New FileSystemObject
fso.CopyFile "file name", "to", Overwrite (true/false)

Note you need to include a reference to the Windows Script Host

No you dont FileCopy is a VBA function.


Bob,

Ive just done a couple of tests with the function and can find no critical problems with what you are trying to do.

I suggest you do as the error message suggests and check both the paths and source file exist.


Code:
Function Nightly()

     Dim CurrentDate As String
     CurrentDate = Format(now,"MMDDYY")  'should be DDMMYY, unless you are american

     FileCopy "\\nel\mfsc-dsndm-d\Nightly.rpt", "\\netapp3\ds-mfsas-d\Backup Secure\Nightly" & CurrentDate & ".rpt"

End Function


:cool:
 
Last edited:

modest

Registered User.
Local time
Today, 06:25
Joined
Jan 4, 2005
Messages
1,220
Shadez said:
No you dont FileCopy is a VBA function

For my code you do, as i suggested using Windows's File System Object. There are ways to access the filesystemobject without actually using the reference file, by using the CreateObject() method.

Shadez, please read my post before you comment on it.
 

Shadez

Registered User.
Local time
Today, 11:25
Joined
Jan 20, 2003
Messages
192
modest said:
Shadez, please read my post before you comment on it.

I did and was forced to respond the way i did, your post offered no help, if you are suggesting he use the FSO instead of the VBA functions then you should say so and not just post a couple of lines that probably mean nothing to bob and will just confuse him.

besides why get him to rewrite his code when the problem is clearly one to do with the paths used and not the code.
 

ipr1

Registered User.
Local time
Today, 11:25
Joined
Jun 13, 2003
Messages
31
THANKS everybody - I finally got it to work. The problem was in the destination file name (I concatenated the name using a SPACE where, in fact, I should have used an underline.

The correct function is as follows:


Function Nightly()


Dim CurrentDate As String
CurrentDate = Date
CurrentDate = Format(CurrentDate, "MMDDYY")

'FileCopy "\\nel\mfsc-dsndm-d\Nightly.rpt", "\\netapp3\ds-mfsas-d\Backup Secure\Nightly.rpt"
FileCopy "\\nel\mfsc-dsndm-d\Nightly.rpt", "\\netapp3\ds-mfsas-d\BackupSecure\Nightly" & "_" & CurrentDate & ".rpt"
End Function
 

ipr1

Registered User.
Local time
Today, 11:25
Joined
Jun 13, 2003
Messages
31
THANKS everybody - I finally got it to work. The problem was in the destination file name (I concatenated the name using a SPACE where, in fact, I should have used an underline.

The correct function is as follows:


Function Nightly()


Dim CurrentDate As String
CurrentDate = Date
CurrentDate = Format(CurrentDate, "MMDDYY")

'FileCopy "\\nel\mfsc-dsndm-d\Nightly.rpt", "\\netapp3\ds-mfsas-d\Backup Secure\Nightly.rpt"
FileCopy "\\nel\mfsc-dsndm-d\Nightly.rpt", "\\netapp3\ds-mfsas-d\BackupSecure\Nightly" & "_" & CurrentDate & ".rpt"
End Function
 

ghudson

Registered User.
Local time
Today, 06:25
Joined
Jun 8, 2002
Messages
6,195
Try this [see blue code] ...

Code:
Function Nightly()

FileCopy "\\nel\mfsc-dsndm-d\Nightly.rpt", "\\netapp3\ds-mfsas-d\Backup Secure\Nightly_[COLOR=Blue]" & Format(Date, "MMDDYY") & "[/COLOR].rpt"

End Function

You can use the Dir() function to verify if the source file is valid.
Code:
If Dir("\\nel\mfsc-dsndm-d\Nightly.rpt") <> "" Then
     msgbox "file exists"
Else
     msgbox "file does not exist"
     Exit Sub 'quit the sub if the file does not exist
End If
 

modest

Registered User.
Local time
Today, 06:25
Joined
Jan 4, 2005
Messages
1,220
Shadez said:
if you are suggesting he use the FSO instead of the VBA functions then you should say so
It seems as though I need to baby you and Shadez. I'll note the next time I post a possible solution, I will write an essay for you to read. If the problem is with the file name, there is nothing we can do. He should know what the file name is and should have looked to see if he inputted the correct name before posting(since that is what the error message said was the problem)... psychics are somewhat of a rarity amongst programmers.


besides why get him to rewrite his code when the problem is clearly one to do with the paths used and not the code.
Many reasons. But the first is that by rewriting, you'll discover something that you did not notice before (such as misspellings). Second, it gets you to rethink your whole approach. Third, unless specified is is often helpful to see other ways of doing things, if not just for learning.

He might come across the filesystemobject in the future and not recognize what it is... in this case he'll remember this post and see a way to call it and something you can do with it.

Sorry shadez, everyone isn't a preschool genius like you.
 

meboz

Registered User.
Local time
Today, 20:25
Joined
Aug 16, 2004
Messages
71
Well look at this, Modest is causing more trouble.

Is there possibly a way that the Moderator can have you barred from making comment in these forums?
 

Shadez

Registered User.
Local time
Today, 11:25
Joined
Jan 20, 2003
Messages
192
modest said:
It seems as though I need to baby you and Shadez. I'll note the next time I post a possible solution, I will write an essay for you to read. If the problem is with the file name, there is nothing we can do. He should know what the file name is and should have looked to see if he inputted the correct name before posting(since that is what the error message said was the problem)... psychics are somewhat of a rarity amongst programmers.

no need for an essay just a line of text saying something like, "personally I would use the fso, this is how you do it". If he has not used the fso before he would have to be psychic to tell what you were trying to say.

modest said:
Many reasons. But the first is that by rewriting, you'll discover something that you did not notice before (such as misspellings). Second, it gets you to rethink your whole approach. Third, unless specified is is often helpful to see other ways of doing things, if not just for learning.

i cant deny that there may be benefits to rewriting code. But you dont rewite code unless there is a good reason.

modest said:
He might come across the filesystemobject in the future and not recognize what it is... in this case he'll remember this post and see a way to call it and something you can do with it.

only because i told you what a load of **** your post was and have explained for you what you were saying. The post by its self would not be remembered because it doesnt solve his problem, just confuse him.

modest said:
Sorry shadez, everyone isn't a preschool genius like you.

Modest grow up and stop being so childish, if you cant take constructive criticism then i suggest you post else ware.
 

modest

Registered User.
Local time
Today, 06:25
Joined
Jan 4, 2005
Messages
1,220
I think I must leave, you all obviously have nothing better to do with your time and I can't be arguing with idiots all day. If the moderator could, I'd have them block/filter out morons from the forum. But since they can't, I would rather them just delete all these off-topic posts. Including my own.
 

Shadez

Registered User.
Local time
Today, 11:25
Joined
Jan 20, 2003
Messages
192
modest said:
I think I must leave, you all obviously have nothing better to do with your time and I can't be arguing with idiots all day. If the moderator could, I'd have them block/filter out morons from the forum. But since they can't, I would rather them just delete all these off-topic posts. Including my own.



:rolleyes:

LOL do you know anything......


you dont need a moderator to block/filter ppl from the forum, there is a simple ignore list that you can edit your self :p :D

as for the idot comment, i didnt see you spot the error in bobs code or even know how to ignore ppl in a forum.....




:p :cool:
 

modest

Registered User.
Local time
Today, 06:25
Joined
Jan 4, 2005
Messages
1,220
Shadez said:
as for the idot comment, i didnt see you spot the error in bobs code or even know how to ignore ppl in a forum.....

This is hopefully my last post. I'm sure you're going to try and get the last word, so you can have it if you want.

First: It's idiot, not "idot"

Second: You can't spot a spelling error.. if the error says "no reference included" my first thought would be... there is not a reference. The same thing went for his error, it said path not found, which means there is something messed up with string. None of us can be the one to say how a non-system folder is spelled.

Third: You're a moron for doing the tests in the first place. You shouldn't have had to do the tests. You should have just been able to look at the code and see if the programming syntax was correct (and it was). Therefore my suggestion should have got him to retype his code and hopefully got him to find his error.

Finally: My suggestion was that that the moderators block you from the forum all together if it was possible. This goes beyond ignore. This prevents you from posting an unintelligent comment ever again, additionally it will prevent you wasting server space/bandwidth. I stick to what I said.

I'll end on the quote, "You are but a fool to reason with a fool." -- I guess I'm a fool for trying.
 

Shadez

Registered User.
Local time
Today, 11:25
Joined
Jan 20, 2003
Messages
192
modest said:
This is hopefully my last post. I'm sure you're going to try and get the last word, so you can have it if you want.

First: It's idiot, not "idot"

You really hit the bottom if you have to point out simple typing errors and use them to boost your already failing argument.

Second: You can't spot a spelling error.. if the error says "no reference included" my first thought would be... there is not a reference. The same thing went for his error, it said path not found, which means there is something messed up with string. None of us can be the one to say how a non-system folder is spelled.

lol did i not say that in my first post :rolleyes:, again i dont see in your post any mention of a path problem.

Third: You're a moron for doing the tests in the first place. You shouldn't have had to do the tests. You should have just been able to look at the code and see if the programming syntax was correct (and it was). Therefore my suggestion should have got him to retype his code and hopefully got him to find his error.

Could you say with 100% certainty say the problem was not to do with the changing of the filename, the use of network paths or possibly invalid characters. This is what i checked to confirm the limitations of the function to see if a rewrite was needed in this situation, which it wasnt.(tbh its not a function ive used before, and i prefer to be safe and not look like a idiot who doesn't solve the problem). Your suggestion, if you can call a badly written function reference a suggestion? would of had him rewriting his code unnecessary. He may of spotted the problem in the process but more likely would copy and paste the paths and end up reposting with a similar problem.

Finally: My suggestion was that that the moderators block you from the forum all together if it was possible. This goes beyond ignore. This prevents you from posting an unintelligent comment ever again, additionally it will prevent you wasting server space/bandwidth. I stick to what I said.

As you please, i have reported this thread to the mods we will see what they have to say.

I'll end on the quote, "You are but a fool to reason with a fool." -- I guess I'm a fool for trying.

I think the quote you were looking for is;

Dont Argue with an idiot they will drag you down to their level and beat you with experience..............
 
Last edited:

Jon

Access World Site Owner
Staff member
Local time
Today, 11:25
Joined
Sep 28, 1999
Messages
7,384
Let us keep cool heads on this forum please.
 
Status
Not open for further replies.

Users who are viewing this thread

Top Bottom