errorkeeps occuring

Dannyc989

Registered User.
Local time
Today, 19:44
Joined
Dec 18, 2013
Messages
46
I keep having an error occurring when I use this module and I cant work out why, I have made reference to the Microsoft scripting runtime etc can anyone help please

Function CopyFolder()

Dim fso As Scripting.FileSystemObject
Dim sSourceDir As String, sDestinationDir As String

Setfso = New Scripting.FileSystemObject

sSourceDir = Forms!Project_Numbers_1!Quote_File_Directiry_Ref
sDestinationDir = Forms!Project_Numbers_1!Files_Directory


fso.CopyFile sSourceDir, sDestinationDir, True

MsgBox "Files copied"
End Function

The error I get is as follows
Run Time Error '438'
object does not support this property or method

I thought I had this cracked ready for presentation tomorrow and am now panicing a bit if anyone can help please do......
 
sorry forgot to say the debug says it is happening on the

Setfso = New Scripting.FileSystemObject

line of the code
 
looks like you need a space after set

Set fso = New Scripting.FileSystemObject
 
Thanks for that... that bit worked a treat...

I have altered the code slightly as I had some issues after this missing a space issue but now I have an issue with the part at the bottom

please see code below:

Sub CopyFolder()

Dim fso As Scripting.FileSystemObject
Dim sSourceDir As String, sDestinationDir As String

Set fso = New Scripting.FileSystemObject

sSourceDir = [Forms]![Project Numbers1]![Quote File Directory Ref]
sDestinationDir = Forms![Project Numbers1]![Files Directory]

fso.CopyFolder sSourceDir, sDestinationDir, True

MsgBox "Folder copied"​
End Sub

the piece in red is saying:

Run-time error (76)
Path not found

the path shows up in the text field on the form as below:

C:\Users\Daniel\Desktop\NT Quotes\10_Test 1_

this is for test purposes and the actual path when this database is put back in operation will be different.

but I know the folder is there as I can physically see it in the path any ideas what this could be. I really want to get this sorted and have never really gotten into access but am liking what can be done with it so if anyone can help I would be most greatful...
 
not clear from your post whether it is the source directory or destination directory not found.

The syntax looks correct so I would check the variables have been assigned and created properly and you have access to the appropriate directories
 
Forgive my novice ability how and where would I check this??
 
a number of ways, either

1. before the copyfolder line put

msgbox sSourceDir
msgbox sDestinationDir

then run the code by clicking a button or whatever you do, then click through the messages

or

2. in the code insert a breakpoint - to do this place the cursor on the copyfolder line and hit F9 - this will highlight the line in maroon and put a large dot in the grey bar to the left

then run the code by clicking a button or whatever you do, the code will stop running at the breakpoint and hightlight the row in yellow. with you mouse, hover over sSourceDir and then sDestinationDir and the values will show

or whilst the code is still in break mode open the immediate window if not already open (hit ctrl-G or select from view menu) then type the following

?sSourceDir
followed by return which will display the value below
then type
?sDestinationDir
followed by return which will display this value

Once you have verified the values, you can
stop the code from continuing by clicking on the square reset button or ctrl-Break
continue a row at a time by hitting the F8 button
continue to the end of the code by hitting the F5 button

or
3. before the copyfolder line put

debug.print sSourceDir
debug.print sDestinationDir

then run the code by clicking a button or whatever you do. debug.print will display the results in the immediate window
 
Ok I did the first option and it gave me back the correct paths in the message boxes but still isn't copying the folder from the source to destination it isn't giving me anything to suggest which of the 2 is giving the error.... I have seen on one thread somewhere something at the end which looked a little similar to below:

*.*

But have no idea what that will do...
 
with regards *.* research access wildcards and in respect of what you are trying to do is irrelevant

correct paths in the message boxes but still isn't copying the folder from the source to destination it isn't giving me anything to suggest which of the 2 is giving the error
suggest temporarily hardcode first the source and then the destination. I also suggest removing the true for now as well. Hardcoding means

fso.CopyFolder "C:\mydirectory", sDestinationDir

Note there should not be a \ at the end
 

Users who are viewing this thread

Back
Top Bottom