Like I mentioned, this is only part of the code I use in my application. You will need to adjust it to suit your app. Also, you can post your code examples here using tags. The tags will preserve the formatting and make it easier for others to look at, copy, edit, etc.
Go Advanced then use the hashtag/pound symbol to insert tags. Then paste your code within the "Code" tags.
The End If exception is because you have code that starts an If Then statement but does not close/end it.
Code:
If strFileName = "" Then 'validation requires strFileName to be initialized as empty string
MsgBox "No file found. Import Failed!", vbCritical, "Try Again"
Exit Sub
End If
This example replaces Else with End If. The idea is to exit the procedure is a file does not exist in the folder.
Beyond that you are going to need some string variables
strFileName
and
strPath
Need to be declared and you need to set them to equal something. This is critical because you do not want to Kill the wrong file on your computer.
Dim strPath as string
strPath = "C:\TestFolder\"
Dim strFileName as string
strFileName = ""
Make sure you know what you are doing before you Kill strPath.
Perhaps commenting out the Kill and Loop until after you test a single file import.
Code:
'Do While strFileName <> "" 'will cause to loop through all csv files in path
DoCmd.TransferText acImportDelim, "FasTrakSpec", _
"tblFasTrakHistory", strPath & strFileName, 0
'Kill strPath & strFileName 'Delete the first csv file after importing
'strFileName = Dir(strPath + "*.csv", vbHidden) 'see if there is another csv file
'Loop 'Rinse and Repeat
This code uses my previous example and shows how to comment out the loop/iteration and the kill