Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FileCopy for access in vb 2

Status
Not open for further replies.

iroosma

Technical User
Jun 25, 2004
11
0
0
US
I am trying to copy several files from a network to the C drive. I am currently using this code.

FileCopy "N:\tam\ins.dbf", "C:\Horizon\ins.dbf"

This works sometimes on some files but not on others. I am copying all the files by just changing the 'ins' to whatever the dbf file I am copying is. I can copy all the files manually but I can not get my code to copy them for me. The files that do not always copy give me an error message that says #70 permisson denied. Is there a way to set permissions in the code so that the files will always copy or is there something else I might be missing?

Thanks
 
Perhaps XCopy is still around? If you are calling a DOS script. If this is for vba related code, then investigate the File Scripting Object. hthw,

Steve Medvid
"IT Consultant & Web Master"

Chester County, PA Residents
Please Show Your Support...
 
More of an OS question than Access...

Permission denined could mean several things.
- network security
- file attribute
- file is busy
- file handle is messed (system thinks file is open but it is not -- requires a reboot)

And yes, please use XCOPY -- it is still around.

If you continue to have problems, tell us what is the OS of your desktop and server.

Richard
 
I tried using XCOPY but it didnt work. I looked it up and the code should be something similar to

XCOPY "N:\tam\ins.dbf", "C:\Horizon\ins.dbf"

I am programming in visual basic within access and I get an error that says "sub or function not identified" and it highlights XCOPY. Any help on how to use XCOPY in access would be greatly appreciated.

thanks

P.S.
I am using Microsoft XP and I suspect that the file might be opened somewhere else. Is there a way to copy the file even if it is open.
 
You may have to reference the full command line with the path to get XCOPY to work - this is a problem encountered running a script. And your syntax is slightly wrong....
[tt]
c:\Windows\System32\XCOPY N:\tam\ins.dbf C:\Horizon\ /Y
[/tt]

- No comma between source and traget.
- Since destination and source have the same file name, you do not have to specifically give it in the command line.

To over-write the target file without being prompted, use the /Y switch.

It would be helpful to know what your networking operating system is.

Backing up open files is tough. It is best to close the file before copying it. You may get away with backing up an open file, or you may have issues even if you don't get a permission error.

Are you trying to backup your Access database? There are some excellent posting on this issue in this forum.

Richard



 
FileCopy is an inbuildt statement, xcopy is a DOS command, which needs to be executed thru Shell or something.

I'm thinking in the lines of Willer's first reply, there might be some OS related things. One thing to try, though, is the CopyFile method of the FileSystemObject, which circumvents some of the limitations of the FileCopy statement, but then has some of it's own;-), perhaps something like this:

[tt]dim fs as object
set fs = createobject("scripting.filesystemobject")
if fs.fileexists("N:\tam\ins.dbf") then
fs.copyfile "N:\tam\ins.dbf", "C:\Horizon\ins.dbf", True
end if
set fs = nothing[/tt]

Roy-Vidar
 
I would highly recommend using the File Scripting Object that RoyVidar illustrated. The one comment is that I would place a check to see if the file actually exists after the copy. I've encountered situations where, due to network latency, the copy command failed.

I also recommend using UNC as opposed to hard-fixed drive letter representations. For example, N:\tam\ins.dbf, would be \\servername\sharedirectoryname\tam\ins.dbf. What if a user has different drive letter mappings? or the network group re-assigns network drive letters? Best to think ahead.

htwh,

dim fs as object
set fs = createobject("scripting.filesystemobject")
if fs.fileexists("N:\tam\ins.dbf") then
fs.copyfile "N:\tam\ins.dbf", "C:\Horizon\ins.dbf", True
DelayTime 4 'Give File Time to be created
If fs.fileexists("C:\Horizon\ins.dbf") = False then
msgbox("File Copy Failed")
'Or another option is to have a loop that keeps checking until file exists and set a counter to check 50 times.
End if
end if
set fs = nothing


Public Function DelayTime(PauseTime As Double)
'sometimes used to slow the program down and allow for screen updating or
'other processes to catch up
Dim start
'PauseTime = 4 ' Set duration.
start = Timer ' Set start time.
Do While Timer < start + PauseTime
DoEvents ' Yield to other processes.
Loop

End Function

Steve Medvid
&quot;IT Consultant & Web Master&quot;

Chester County, PA Residents
Please Show Your Support...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top