Gary-
You're not changing the Name variable inside the Do loop. Like this:
Private Sub Command0_Click()
Dim InputDir As String, ImportFile As String, tblName As String
Dim InputMsg As String, Name As String
InputMsg = "Type the pathname of the folder that contains "
InputMsg = InputMsg & "the files you want to import."
InputDir = InputBox(InputMsg)
' Change the file extension on the next line for the
' type of file you want to import.
ImportFile = Dir(InputDir & "\*.txt")
Do While Len(ImportFile) > 0
Name = ((InputDir) & ("\") & (ImportFile))
' Use the import file name without its extension as the table
' name.
tblName = "Expenses"
DoCmd.TransferText [acImportDelim], "Batch", "ExpBatch", Name
ImportFile = Dir
Loop
End Sub
John Viescas, author
Building Microsoft Access Applications
Microsoft Office Access 2003 Inside Out
Running Microsoft Access 2000
SQL Queries for Mere Mortals
http://www.viescas.com/
(Paris, France)
For the inside scoop on Access 2007, see:
http://blogs.msdn.com/access/
_____
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf
Of Gary E. Daniels
Sent: Friday, June 23, 2006 4:23 AM
To: [email protected]
Subject: [ms_access] Batch Import Problem
Hi, I need some help. The routine below runs when a command button is
clicked. A prompt appears to enter the directory path to the folder
containing delimited text files to be imported into an Access 97
table. The test folder contains 9 files. The problem is that the 1st file
is imported 9 times into the table. How do I correct the routine so it
loops properly and imports each file? Thanks in advance.
Gary
Private Sub Command0_Click()
Dim InputDir, ImportFile As String, tblName As String
Dim InputMsg, Name As String
InputMsg = "Type the pathname of the folder that contains "
InputMsg = InputMsg & "the files you want to import."
InputDir = InputBox(InputMsg)
' Change the file extension on the next line for the
' type of file you want to import.
ImportFile = Dir(InputDir & "\*.txt")
Name = ((InputDir) & ("\") & (ImportFile))
Do While Len(ImportFile) > 0
' Use the import file name without its extension as the table
' name.
tblName = "Expenses"
DoCmd.TransferText [acImportDelim], "Batch", "ExpBatch", Name
ImportFile = Dir
Loop
End Sub
Gary E. Daniels
Cornerstone Appraisal Company
500 Selkirk Drive
Schaumburg, IL. 60194
847 882-5892 Fax 847 882-5963
mailto:[EMAIL PROTECTED] <mailto:gdaniels%40ais.net> net
http://www.askdata. <http://www.askdata.net> net
[Non-text portions of this message have been removed]
------------------------ Yahoo! Groups Sponsor --------------------~-->
Something is new at Yahoo! Groups. Check out the enhanced email design.
http://us.click.yahoo.com/SISQkA/gOaOAA/yQLSAA/q7folB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ms_access/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/