FileCopy Problem

A

Alan

I have a so far been able to copy one file at a time with
this code below but I need to be able to copy and move a
range of files the files that the user would type in the
form the names would be like pt071603, pt071503, pt071403.
(no file extensions) The number of files could be as many
as 16 files that would needed to be copy and moved.

I am not sure how to include a parameter to this code or
if it can be done can anyone help me please.


Private Sub Command2_Click()
On Error GoTo Err_Command2_Click
Dim Text_FileName As String

FileCopy "C:\1\" & Me.Text_FileName, "C:\1old\" &
Me.Text_FileName
Kill "C:\1\" & Me.Text_FileName
MsgBox ("Complete")

Exit_Command2_Click:
Exit Sub

Err_Command2_Click:
MsgBox Err.Description
Resume Exit_Command2_Click

End Sub
 
H

HSalim

you would be better off reading the list of file available to move into a
temp table or even a multi-select list box and allowing the user to select
which files should be moved.

but as is, let us say you are using a textbox with a comma-separated list of
filenames:

Dim Text_FileName As String
dim Myarray, i as integer

MyAray = Split(Me.Text_fileName)

for i = 0 to ubound(MyArray)

FileCopy "C:\1\" & myarray(i), "C:\1old\" & myarray(i)
Kill "C:\1\" & myarray(i)
MsgBox ("moved " & myarray(i))
next
msgbox "Complete"
 
A

Alan

-----Original Message-----
you would be better off reading the list of file available to move into a
temp table or even a multi-select list box and allowing the user to select
which files should be moved.
What you said above is what I would like to end up with,
but I could not figure out how to do it. So I went with
what I thought would be easyier do and would be needed to
be done to end up with what you said. As you may have
guessed I am trying to learn as I go. (means I make lots
of mistakes along the way)

Your code did not work for me I got an error Type
Mismatch, would it be from dim Myarray, i as integer?
 
H

HSalim

ok, here is the code again - I made a mistake while writing it out

Dim MyArray, i As Integer

MyArray = Split(Filenames, ",")

For i = 0 To UBound(MyArray)

FileCopy "C:\1\" & Myarray(i), "C:\1old\" & Myarray(i)
Kill "C:\1\" & Myarray(i)
MsgBox ("moved " & MyArray(i))
Next
MsgBox "Complete"
 
A

Alan

Forgot to include the line that is causing the mismatch
problem here it is. I am unsure what to do to fix it

For i = 0 To UBound(Myarray)
 
H

HSalim

I had posted a anoter reply but it has gone into some internet wormhole, so
here is the reply again:

Alan,
Here is some sample code from Ken that is used to read file names from a
directory
have a form with the subform
subform's recordset should be the table you populate from below.
Table should have a yes no field as well, allowing the user to check which
files should be moved
form should have a command button that on click, traverses the subform's
recordset and moves the selected files

Good luck
HS
 

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