Automating file import

  • Thread starter Thread starter Christopher
  • Start date Start date
C

Christopher

Hello,
I am using a macro to import a fixed width ".txt" file
into an Access 2000 table. Though the path to the file
remains constant, a new file (with a new file name) needs
to be imported each day. Is there a way to have Access
either A)prompt for the file name when the macro is run or
B)have the file name be an expression which refers to a
text box in a form? I would prefer that users do not have
to make changes to the macro's argument in order to do the
import. I would greatly appreciate any advice. Thanks.
 
How to Import all Files in a Folder:

Private Sub btnImportAllFiles_Click()
'procedure to import all files in a directory and delete them.
'assumes they are all the correct format for an ASCII delimited import.
Dim strfile As String

ChDir ("c:\MyFiles")
strfile = Dir("FileName*.*")
Do While Len(strfile) > 0
DoCmd.TransferText acImportDelim, "ImportSpecName", "AccessTableName",
"c:\MyFiles\" & strfile, True
'delete the file (consider moving it to an Archive folder instead.)
Kill "c:\MyFiles\" & strfile
strfile = Dir
Loop

End Sub
 
Back
Top