Importing Text Files

R

rama

Hello,
I am using a command button called “cmdImport” to read the contents of
a text file to my access database. On click event of “cmdImport” will
run this code
DoCmd.TransferText acImportFixed, "Import_Specification", "tblText",
"C:\Import\09FAL1.txt" ‘to import the contents of the file.
I wanted to import similar kind of many files for that I need the code
to read the source file name from a text box in my form called
“txtSourceFile” . Please help me to correct the above code where
source file information should be” Me. txtSourceFile” instead of "C:
\Import\09F09AL1.txt".
Thanks
Rama
 
P

PieterLinden via AccessMonster.com

rama said:
Hello,
I am using a command button called “cmdImport†to read the contents of
a text file to my access database. On click event of “cmdImport†will
run this code
DoCmd.TransferText acImportFixed, "Import_Specification", "tblText",
"C:\Import\09FAL1.txt" ‘to import the contents of the file.
I wanted to import similar kind of many files for that I need the code
to read the source file name from a text box in my form called
“txtSourceFile†. Please help me to correct the above code where
source file information should be†Me. txtSourceFile†instead of "C:
\Import\09F09AL1.txt".
Thanks
Rama

DoCmd.TransferText acImportFixed, "Import_Specification", "tblText", me.
txtSourceFile

If you wanted to process all the text files in a folder, then you could use
DIR to loop over the directory and process them.

Sub ImportAllTextFilesFromDirectory(ByVal strPath as string)
StrFileName = Dir$(strPath) ' Read filespec from a form here???

Do While Len(StrFileName) > 0
DoCmd.TransferText acImportFixed, "Import_Specification",
"tblText"
StrFileName = Dir

Loop

End Sub
 
R

rama

DoCmd.TransferText acImportFixed, "Import_Specification", "tblText", me.
txtSourceFile

If you wanted to process all the text files in a folder, then you could use
DIR to loop over the directory and process them.

Sub ImportAllTextFilesFromDirectory(ByVal strPath as string)
            StrFileName = Dir$(strPath)   ' Read filespecfrom a form here???

            Do While Len(StrFileName) > 0
                DoCmd.TransferText acImportFixed, "Import_Specification",
"tblText"
                StrFileName = Dir

            Loop

End Sub

Hello,
Thank you very much for the response. But code below
DoCmd.TransferText acImportFixed, "Import_Specification", "tblText",
me. txtSourceFile ---- I am getting Compile error ie. Method or
data member not found.

Also the second option to import all files in a directory, which is
much desirable, is also not running. It brings an error : “Procedure
declaration does not match description of event or procedure having
the same name “.
Please help me.
Thanks again
Rama
 

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