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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move file script

Status
Not open for further replies.

mrkipling

Technical User
Apr 26, 2001
16
GB
I am using this script , that is triggered by a form timer, to move csv files into another folder one they have been inputed into a DB table

Set fs = CreateObject("Scripting.FileSystemObject")
'If fs.FileExists("c:\MYDOCS\*.csv") Then
fs.MoveFile "c:\MYDOCS\*.csv", "c:\PROCESSED\"

But i get an error message appear when the script checks the folder, and there are no csv's in the folder to move. Is there a way i can modify this script to ignore the error message.

TIA

Mark
 
You could put an error handler round it..

eg.

Sub Whatever()
On Error GoTo ErrorHandler

Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists("c:\MYDOCS\*.csv") Then
fs.MoveFile "c:\MYDOCS\*.csv", "c:\PROCESSED\"


Exit Sub

ErrorHandler:

If Err.Number = x Then
Exit Sub ' or resume next
End If
End Sub

You will need to substitute x for the number of the error returned by the error you are getting. And Either Exit Sub in the If Statement if you don't want to do anything else or Resume next will cause the Sub to keep executing from the line of code after the one that caused the error.

Hope this helps.

There are two ways to write error-free programs; only the third one works.
 
Thanks alot G holden, never used error handlers before, works fine now .

Thanks again

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top