Filecopy problem

Filecopy problem

Post by Jay » Wed, 15 Mar 2006 13:01:44


I am not sure if I am in the right news group for this question.
I am having a problem with the filecopy in access.
I would like to use the filecopy for text files to backup and import into
access and then make queries for forms.

Here is what I have so far:



Dim source As String
Dim target As String

source = "a:\test.txt"
target = "C:\Documents and Settings\UserAccount\Desktop\test.txt"

FileCopy source, target


End Sub




I can copy from folders on my harddrive, but not from the A Drive.
I tried on 3 other computers and I get the same error.

If I change the code to the following, it copies:




Dim source As String
Dim target As String

source = "C:\test.txt"
target = "C:\temp\test.txt"

FileCopy source, target

End Sub




It looks like the problem is the target

target = "C:\Documents and Settings\UserAccount\Desktop\test.txt"

Any solution would be wonderfull.
 
 
 

Filecopy problem

Post by Rob Parke » Wed, 15 Mar 2006 21:17:45

Hi Jay,

Your problem lies in the string you have for the target destination. Unless
your user has a windows login name of "UserAccount", the target destination
will not exist. What you need to do is dynamically get the UserAccount name
and put that into the target string.

There is a function available on the AccessWeb site which will give you the
user name; see http://www.yqcomputer.com/

Put this into a module in your database, and then construct the target
string dynamically for the current user, thus:

target = "C:\Documents and Settings\" & fOSUserName &
"\Desktop\test.txt"

HTH,

Rob

 
 
 

Filecopy problem

Post by Jay » Thu, 16 Mar 2006 10:39:50


Thanks. I will try it.
 
 
 

Filecopy problem

Post by Jay » Fri, 17 Mar 2006 11:24:40


All is well. It is working. Thanks again.