PC Review


Reply
Thread Tools Rate Thread

FileCopy Command Giving "Subscript Out of Range" Error Message

 
 
=?Utf-8?B?SmltIEhhZ2Fu?=
Guest
Posts: n/a
 
      15th Jun 2005
I am using the following statements to copy a file from one location to
another and getting an error message "subscript out of range" on the FileCopy
command. (Note: I used a bunch of debug.print statements to determine the
offending line).

Dim ofsFileSys As New FileSystemObject

If ofsFileSys.FileExists(SourceFile) Then
FileCopy SourceFile, DestinationFile ' Copy source to
destination
end if

Both the Source and Destination files exist on the same network drive.

The SourceFile is being created by a data acquisition system and is updated
every few seconds. My macro is programmed to copy the latest SourceFile to
the DestinationFile every 20 seconds or so and grab the latest data entry
from the newly created DestinationFile.

For the most part, the macro works fine. But every so often I get the
"Subscript Out of Range" error message associated with the FileCopy command.
I cannot go into the debugger and repeat the error, since it seems to occur
randomly.

I suspect the problem lies with copying the file and the same time it is
being updated, but I don't know enough about how files are handled by
Windows.

Any ideas as to what may be causing the problem or suggestions of what to do
about it would be appreciated.

My operating system is Windows 2000.

Thanks for your help,

Jim





 
Reply With Quote
 
 
 
 
=?Utf-8?B?RGFtb24gTG9uZ3dvcnRo?=
Guest
Posts: n/a
 
      15th Jun 2005
Try adding an error handler. If your routine coincides with the file
creation, wait a few seconds and try again or wait for the next 20 second
interval.

On Error Resume Next


"Jim Hagan" wrote:

> I am using the following statements to copy a file from one location to
> another and getting an error message "subscript out of range" on the FileCopy
> command. (Note: I used a bunch of debug.print statements to determine the
> offending line).
>
> Dim ofsFileSys As New FileSystemObject
>
> If ofsFileSys.FileExists(SourceFile) Then
> FileCopy SourceFile, DestinationFile ' Copy source to
> destination
> end if
>
> Both the Source and Destination files exist on the same network drive.
>
> The SourceFile is being created by a data acquisition system and is updated
> every few seconds. My macro is programmed to copy the latest SourceFile to
> the DestinationFile every 20 seconds or so and grab the latest data entry
> from the newly created DestinationFile.
>
> For the most part, the macro works fine. But every so often I get the
> "Subscript Out of Range" error message associated with the FileCopy command.
> I cannot go into the debugger and repeat the error, since it seems to occur
> randomly.
>
> I suspect the problem lies with copying the file and the same time it is
> being updated, but I don't know enough about how files are handled by
> Windows.
>
> Any ideas as to what may be causing the problem or suggestions of what to do
> about it would be appreciated.
>
> My operating system is Windows 2000.
>
> Thanks for your help,
>
> Jim
>
>
>
>
>

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmltIEhhZ2Fu?=
Guest
Posts: n/a
 
      15th Jun 2005
Thanks Damon,

I did have an error handler in the subroutine, but it apparently didn't
capture the error. Interestingly enough, the error handler from the calling
routine is the one that reported the error. Which gets me thinking that
perhaps the error handler in the subroutine has an error in it as well!!
I'll check this out. Thanks for your help.

Jim


"Damon Longworth" wrote:

> Try adding an error handler. If your routine coincides with the file
> creation, wait a few seconds and try again or wait for the next 20 second
> interval.
>
> On Error Resume Next
>
>
> "Jim Hagan" wrote:
>
> > I am using the following statements to copy a file from one location to
> > another and getting an error message "subscript out of range" on the FileCopy
> > command. (Note: I used a bunch of debug.print statements to determine the
> > offending line).
> >
> > Dim ofsFileSys As New FileSystemObject
> >
> > If ofsFileSys.FileExists(SourceFile) Then
> > FileCopy SourceFile, DestinationFile ' Copy source to
> > destination
> > end if
> >
> > Both the Source and Destination files exist on the same network drive.
> >
> > The SourceFile is being created by a data acquisition system and is updated
> > every few seconds. My macro is programmed to copy the latest SourceFile to
> > the DestinationFile every 20 seconds or so and grab the latest data entry
> > from the newly created DestinationFile.
> >
> > For the most part, the macro works fine. But every so often I get the
> > "Subscript Out of Range" error message associated with the FileCopy command.
> > I cannot go into the debugger and repeat the error, since it seems to occur
> > randomly.
> >
> > I suspect the problem lies with copying the file and the same time it is
> > being updated, but I don't know enough about how files are handled by
> > Windows.
> >
> > Any ideas as to what may be causing the problem or suggestions of what to do
> > about it would be appreciated.
> >
> > My operating system is Windows 2000.
> >
> > Thanks for your help,
> >
> > Jim
> >
> >
> >
> >
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FileCopy command using FileDialog Box LarryE Microsoft Access VBA Modules 8 3rd Jan 2010 10:52 PM
Run Time Error 53 on FileCopy command justin.arnold2@gmail.com Microsoft Excel Programming 10 12th Mar 2008 05:51 PM
Out of Office Assistant giving error message Joy Microsoft Outlook 2 30th Jun 2004 05:18 AM
LAN and Internet in XP Pro_Modem giving 651 error+NIC giving out [no valid address] new2_XP Windows XP General 9 20th Mar 2004 04:37 PM
LAN and Internet in XP Pro_Modem giving 651 error+NIC giving out [no valid address] new2_XP Windows XP Customization 1 17th Mar 2004 11:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:13 AM.