Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 02-07-2003, 11:14 AM   #1
MikeAngelastro
Registered User
 
Join Date: Mar 2000
Location: Salt Lake, Utah
Posts: 254
Thanks: 0
Thanked 0 Times in 0 Posts
MikeAngelastro
FileSystemObject Problem

Hi,

I am importing files that I want to move to another folder after the import is complete. I tried the MoveFile method and I get an error 70 for permission denied. I then tried the CopyFile method with the idea of deleting the file after the copy. The copy works but the delete doesn't and throws the same error. Anyone have any idea why? The code I am using is below.

Dim fs As New FileSystemObject

'Move imported file to the imported file folder.
Source = FileName
Destination = IMPORTED_PO_FOLDER & Dir$(FileName)

'This works.
fs.CopyFile Source, Destination

'This does not work - error: 70 - Permission denied.
'The FileExists works.
If fs.FileExists(Destination) Then fs.DeleteFile (Source)

'This does not work - error: 70 - Permission denied.
fs.MoveFile Source, Destination

Thanks,

Mike

MikeAngelastro is offline   Reply With Quote
Old 02-07-2003, 12:12 PM   #2
pono1
Newly Registered User
 
Join Date: Jun 2002
Posts: 1,186
Thanks: 0
Thanked 0 Times in 0 Posts
pono1 will become famous soon enough
Mike,

Without a hard look at the code, here's a guess.

Your commands:
Copy -- this works
Move (which is a copy and a delete operation) -- doesn't work
Delete -- doesn't work

Do you have full permissions on the source folder? In Windows Explorer, right click the source folder, click Properties, then the Security tab to figure it out.

Regards,
Tim
pono1 is offline   Reply With Quote
Old 02-10-2003, 12:39 PM   #3
MikeAngelastro
Registered User
 
Join Date: Mar 2000
Location: Salt Lake, Utah
Posts: 254
Thanks: 0
Thanked 0 Times in 0 Posts
MikeAngelastro
Hi Pono1,

Yes, I do have full permissions on the source folder. In fact I am able to manually cut and past from the source folder to the destination folder.

Thanks,

Mike

MikeAngelastro is offline   Reply With Quote
Old 02-10-2003, 01:36 PM   #4
pono1
Newly Registered User
 
Join Date: Jun 2002
Posts: 1,186
Thanks: 0
Thanked 0 Times in 0 Posts
pono1 will become famous soon enough
Mike,

Try code like this:
Code:
Dim fs As Variant
Set fs = CreateObject("Scripting.FileSystemObject")
  
Dim strSource As String
Dim strDestination As String

'get source and destination
strSource = "F:\Folder X\X.txt"
strDestination = "F:\Folder Y\"

'copy source to dest
fs.CopyFile strSource, strDestination

'kill source file
fs.deletefile strSource
Also, have you seen this article? It may or may not apply but does offer some work-arounds.

Last thought. Could the file's permissions (as opposed to the folder permissions) be restricting the delete?

Regards,
Tim
pono1 is offline   Reply With Quote
Old 02-11-2003, 01:31 AM   #5
IMO
Now Known as ___
 
IMO's Avatar
 
Join Date: Sep 2002
Location: On a small Asteroid Orbiting Planet Zog, I think!!
Posts: 723
Thanks: 0
Thanked 1 Time in 1 Post
IMO is on a distinguished road
Mike,
Try this, I use this to import and move .csv files.

Dim InputDir, ImportFile As String, tblName As String, FinalName As String
Dim InputMsg As String
InputDir = "c:\YOUR DIRECTORY TO IMPORT FROM\"
ImportFile = Dir(InputDir & "\*.csv")
Do While Len(ImportFile) > 0
'tblName = Left(ImportFile, (InStr(1, ImportFile, ".") - 1)) 'Use this to import each file into separate tables.
tblName = "History" 'I use this to import all my files into one table.
DoCmd.TransferText acImportDelim, , tblName, InputDir & ImportFile, True
ImportFile = Dir
Loop
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
'If fs.FileExists("c:\YOUR DIRECTORY TO IMPORT FROM\*.csv") Then
fs.MoveFile "c:\YOUR DIRECTORY TO IMPORT FROM\*.csv", "c:\YOUR DIRECTORY TO RECEIVE MOVED FILES\"

Let me know how you get on.

IMO
__________________
Now known as ___
IMO is offline   Reply With Quote
Old 02-11-2003, 09:15 AM   #6
MikeAngelastro
Registered User
 
Join Date: Mar 2000
Location: Salt Lake, Utah
Posts: 254
Thanks: 0
Thanked 0 Times in 0 Posts
MikeAngelastro
Pono1 and IMO,

Thanks for all your help.

I opened an empty database for test purposes and found that the code I was using worked with the same paths. This result suggested that there may be some corruption where I had the code. Because moving the file was a small part of a large function that imported it, I retyped the code in the calling sub where the file-move would take place if the import was successful. This worked.

I also found that, if I used the "New" key word when I dimensioned the FileSystemObject, I did not need the "Set" command.

Thanks again for your help.

Mike
MikeAngelastro is offline   Reply With Quote
Old 02-12-2003, 12:26 AM   #7
IMO
Now Known as ___
 
IMO's Avatar
 
Join Date: Sep 2002
Location: On a small Asteroid Orbiting Planet Zog, I think!!
Posts: 723
Thanks: 0
Thanked 1 Time in 1 Post
IMO is on a distinguished road
Glad it all worked out

IMO

__________________
Now known as ___
IMO is offline   Reply With Quote
Old 06-29-2004, 12:37 PM   #8
rcassani
Guest
 
Posts: n/a
I am trying to write a similar routine. Using the code above I always get the error "Object doesn't support this property or method" on the fs.Move statement. Am I missing something?
  Reply With Quote
Old 06-29-2004, 03:59 PM   #9
MikeAngelastro
Registered User
 
Join Date: Mar 2000
Location: Salt Lake, Utah
Posts: 254
Thanks: 0
Thanked 0 Times in 0 Posts
MikeAngelastro
I believe that you do not have a reference to the MS Windows Scripting Host.
MikeAngelastro is offline   Reply With Quote
Old 06-29-2004, 07:49 PM   #10
rcassani
Guest
 
Posts: n/a
Okay, I added the Reference but still get the error. Does it need to be positioned anywhere specific?

FYI, I am able to use the object to search a folder and populate a listbox with all the .xls files in it. I use the fs.Execute method as well as the fs.foundfiles.count method. I only get the error if I try to use the fs.Move, fs.Copy, or fs.Delete methods.

  Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump




All times are GMT -8. The time now is 08:22 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World