Filecopy problem

J

Jay

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.
 
R

Rob Parker

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.mvps.org/access/api/api0008.htm for details.

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
 
J

Jay

Rob said:
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.mvps.org/access/api/api0008.htm for details.

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




Thanks. I will try it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top