CC said:
I did specify the entire file name. Here is the code:
Private Sub Command47_Click()
Dim strFileName As String
strFileName = "a" 'Need to set file name to a non-blank value so
we go into the loop.
Do While strFileName <> ""
strFileName = Dir("C:\Documents and Settings\user1\Desktop\Temp
Files\ImportTesting\*.txt")
If strFileName <> "" Then 'A file was found
MsgBox strFileName
DoCmd.TransferText acImportDelim, , "TableOne", strFileName,
False
End If
Loop
MsgBox "Done"
End Sub
Sorry, but you didn't. The return value of the Dir() function is just the
filename, not the path, so that's all you'd have in strFileName. Your
MsgBox must have shown you that. Modify your code like this:
'----- start of revised code -----
Private Sub Command47_Click()
Const conImportFolder = _
"C:\Documents and Settings\user1\Desktop\Temp Files\ImportTesting\"
Dim strFileName As String
strFileName = Dir(conImportFolder & "*.txt")
Do While Len(strFileName) > 0
If MsgBox( _
"Import file '" & strFileName & "'?", _
vbQuestion+vbYesNo, _
"Import File?") _
= vbYes _
Then
DoCmd.TransferText acImportDelim, , _
"TableOne", conImportFolder & strFileName, _
False
End If
' Get next file to import, if any.
strFileName = Dir()
Loop
MsgBox "Done"
End Sub
'----- end of revised code -----
That's "air code", so I may have made a few mistakes. Also, the long string
literal for conImportFolder may have been wrapped onto two lines by the
newsreader, but should all be on one line.
Note that I've set it up so that it loops through all the .txt files in the
folder, offering to import each one.