Transferring Text Files to a New Folder

R

Resti M. Guay

To Everyone,
I have an access database which organize machine performance data. I gather
all machine data using 3 1/2 floppy disk. When uploading the data, I always
copy the content of my floppy disk to my specific folder location. When I
upload the data from text files, the application check all the text file from
specific location and upload it on my table, and this works fine. But i still
want to add another automation before uploading data and I want it this
way... every time i want to upload the data, i will just key-in my target
folder location and after i run the code it will transfer first the text file
to my folder and upload it.
i need a code for my problem.

I really need your help guys
resti
 
W

Wayne Morgan

How are they displayed in a listbox? By the name and path? If just the name,
do they all have a common path that you're aware of? If so, set the listbox
up as a multiselect listbox and loop through the selected items, copying
them one at a time.

Assuming path and name is in the listbox, this should work. If the path
isn't there, you'll need to concatenate it onto the string.

Dim varItem As Variant, ctl As Control
Dim strSourceFile As String, strDestinationFile As String
Set ctl = Me.lstMyListbox
For varItem in ctl.ItemsSelected
strSourceFile = ctl.ItemData(varItem)
strDestinationFile = "C:\DestinationFolder\"
'Append just the file name to the path
strDestinationFile = strDestinationFile & Mid(strSourceFile,
InStrRev(strSourceFile, "\") + 1)
FileCopy strSourceFile, strDestinationFile
Next
Set ctl = Nothing

If the list box is a multicolumn listbox and the file name isn't in the
Bound Column, you'll need to specify the column.

Example:
strSourceFile = ctl.Column(ColumnNumber, varItem)
Where ColumnNumber is an integer from 0 to one less than the number of
columns (i.e. zero based).
 
R

Resti M. Guay

thanks Wayne. you helped me alot

Wayne Morgan said:
How are they displayed in a listbox? By the name and path? If just the name,
do they all have a common path that you're aware of? If so, set the listbox
up as a multiselect listbox and loop through the selected items, copying
them one at a time.

Assuming path and name is in the listbox, this should work. If the path
isn't there, you'll need to concatenate it onto the string.

Dim varItem As Variant, ctl As Control
Dim strSourceFile As String, strDestinationFile As String
Set ctl = Me.lstMyListbox
For varItem in ctl.ItemsSelected
strSourceFile = ctl.ItemData(varItem)
strDestinationFile = "C:\DestinationFolder\"
'Append just the file name to the path
strDestinationFile = strDestinationFile & Mid(strSourceFile,
InStrRev(strSourceFile, "\") + 1)
FileCopy strSourceFile, strDestinationFile
Next
Set ctl = Nothing

If the list box is a multicolumn listbox and the file name isn't in the
Bound Column, you'll need to specify the column.

Example:
strSourceFile = ctl.Column(ColumnNumber, varItem)
Where ColumnNumber is an integer from 0 to one less than the number of
columns (i.e. zero based).
 
Top