Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help with FileCopy Function

0 views
Skip to first unread message

Sunflower

unread,
Aug 18, 2010, 11:57:45 PM8/18/10
to
I have a module that works
===========================================================
Public Function CopyMyFile()
FileCopy "G:\Promo\Promo-3-500.jpg", "G:\GameNames
\Game1\3-500\Promo-3-500.jpg"
FileCopy "G:\Promo\Promo-3-500.jpg", "G:\GameNames
\Game2\3-500\Promo-3-500.jpg"
End Function
===========================================================

However, I would like to use the field values in a table instead of
puting in the string value
I have a TABLE with 160 rows

Table Name: tblFILES
Field Name: SourceFile
Field Name: DestinationFile

I have tried the following code but keep getting errors

===========================================================
Public Function CopyMyFile()
FileCopy tblFILES.SourceFile, tblFILES.DestinationFile
End Function
===========================================================

all help greatly appreciated

John W. Vinson

unread,
Aug 19, 2010, 2:10:14 AM8/19/10
to
On Wed, 18 Aug 2010 20:57:45 -0700 (PDT), Sunflower <luvsun...@gmail.com>
wrote:

You can't just refer to a table field in that way. Bear in mind that the table
has 160 rows (and it might have 1,600,000 for all the program knows); you need
some way to specify *which row*. Do you want to copy 160 files? Or a selection
of the files? or what?

GUESSING that you in fact want to loop through the table and copy the file
named in SourceFile to the filename in DestinationFile, you'll need to open a
recordset based on the table and loop through it:

Public Function CopyMyFile()
Dim db As DAO.Database
Dim rs AS DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tblFiles")
Do Until rs.EOF
FileCopy rs!SourceFile, rs!DestinationFile
rs.MoveNext
Loop
End Function

End Function
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com

Sunflower

unread,
Aug 19, 2010, 2:04:15 PM8/19/10
to
On Aug 18, 11:10 pm, John W. Vinson
<jvinson@STOP_SPAM.WysardOfInfo.com> wrote:
> On Wed, 18 Aug 2010 20:57:45 -0700 (PDT), Sunflower <luvsunflow...@gmail.com>

I copied and pasted into my module
I get an error
Run-time error 53
File not found


John W. Vinson

unread,
Aug 19, 2010, 4:18:53 PM8/19/10
to
On Thu, 19 Aug 2010 11:04:15 -0700 (PDT), Sunflower <luvsun...@gmail.com>
wrote:


>I copied and pasted into my module
>I get an error
>Run-time error 53
>File not found

Then presumably there is a record in the table for a file which does not
exist. Is that the case?

You could use the Dir() function to first check to see if the source file in
fact exists; if it does, proceed to do the filecopy, otherwise warn the user
or take appropriate action. You can also use error trapping to detect the 53
error.
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:

Sunflower

unread,
Aug 19, 2010, 5:10:21 PM8/19/10
to
On Aug 19, 1:18 pm, John W. Vinson
<jvinson@STOP_SPAM.WysardOfInfo.com> wrote:
> On Thu, 19 Aug 2010 11:04:15 -0700 (PDT), Sunflower <luvsunflow...@gmail.com>

> wrote:
>
> >I copied and pasted into my module
> >I get an error
> >Run-time error 53
> >File not found
>
> Then presumably there is a record in the table for a file which does not
> exist. Is that the case?
>
> You could use the Dir() function to first check to see if the source file in
> fact exists; if it does, proceed to do the filecopy, otherwise warn the user
> or take appropriate action. You can also use error trapping to detect the 53
> error.
> --
>
>              John W. Vinson [MVP]

I found it!
It now. Works beautifully
I will try to figure out how to code in the Dir() function
Thanks for your help

0 new messages