Solved

VB6 - FileCopy problem.

Posted on 2003-10-27
10
2,764 Views
Last Modified: 2010-08-05
Hi,

I am using filecopy(path,filenam).... to copy MsWord document.

But when the file is open I get error msg.

Any help?


Tks,
Angel
0
Comment
Question by:2Angel
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 9627032
the file is open so it's a problem to overwrite it you can try 2 things

handle the error in a on error trap

on error goto errhandler

....your code

  exit sub
errhandler:
  if err.number = xxx then
    'check if this is the copy error
  else
    'another error
  end if
  exit sub

or use the word vba method where you can use the saveascopy method and application.displayalerts to hide the warnings on overwriting but i think you get the same error here on trying to overwrite an open file
0
 
LVL 2

Author Comment

by:2Angel
ID: 9627074
I alredy use errhandler....

I don't want to overwrite the file I want to copy it to diferent folder whil it's open.
0
 
LVL 2

Author Comment

by:2Angel
ID: 9627081
bytheway, its posible to do so (whil the file is open) siply by using Windows Explorer...
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Accepted Solution

by:
wuttrain earned 50 total points
ID: 9627189
try this:

Option Explicit
Private Declare Function CopyFile Lib "kernel32" _
   Alias "CopyFileA" _
  (ByVal lpExistingFileName As String, _
   ByVal lpNewFileName As String, _
   ByVal bFailIfExists As Long) As Long

Private Sub Command1_Click()

   CopyFile "c:\f.doc", "c:\fback.doc", False

End Sub
0
 
LVL 4

Expert Comment

by:daleyjem
ID: 9628475
can't you just temporarily close the file, then copy it, and open it again?

i'd do something like:

   dim fso as new filesystemobject
' do this loop to make sure the file gets copied before you try to reopen the file
   do until fso.fileexists("c:\thefile")=true
   loop

0
 
LVL 2

Expert Comment

by:wuttrain
ID: 9631356
did you test the API code I suggested?
0
 

Expert Comment

by:Hyperon
ID: 9632689
use dos to do it for you: shell "command.com copy " & filename$ & " " 7 filedest$

where filename$ and filedest$ are the appropriate strings of the filename and the destination
0
 
LVL 4

Expert Comment

by:daleyjem
ID: 9633368
yeah, i think hyperon has a point there...i'd try that
0
 

Expert Comment

by:Hyperon
ID: 9633514
i just prefer dos lol

(and linux, but we won't get onto that, :D)

try that code i suggested, it should work
0
 
LVL 2

Author Comment

by:2Angel
ID: 9633949
wuttrain: It's working very gggggoooooooddddddd

Thank you very much for the help........


Angel
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question