Sub ImportTmpCsvFiles()
Dim FilePath As String
Dim FileSpec As String
Dim Match As String
FilePath = "C:\Temp\"
FileSpec = FilePath & "*.csv"
Match = Dir(FileSpec)
'Make sureCSVfileexists
If Len(Match) = 0 Then
MsgBox "NoCSVFilesFound.", vbInformation, Title
Exit Sub
End If
DoCmd.TransferText acImportDelim, "YourSpecNameHere", "Table1", FilePath &
Match, -1
DoCmd.RunSQL "UPDATE Table1 SET Table1.FileName = """ & Match & """ WHERE
Table1.FileName Is Null"
End Sub
Hi, I found this post and tried it out, because I need this same exact
thing. When I put it together, I can actually get this to run (I
attached it to a command button on a form)
--------------------------------------------------------------------------------------
Private Sub Command0_Click()
Dim FilePath As String
Dim FileSpec As String
Dim Match As String
FilePath = "C:\test\"
FileSpec = FilePath & "*.csv"
Match = Dir(FileSpec)
'Make sure CSV file exists
If Len(Match) = 0 Then
MsgBox "No CSV Files Found.", vbInformation, Title
Exit Sub
End If
DoCmd.TransferText acImportDelim, "myspecs", "tblCSV", FilePath &
Match, -1
DoCmd.RunSQL "UPDATE tblCSV SET tblCSV.FileName = """ & Match & """
WHERE tblCSV.FileName Is Null"
Match = Dir
End Sub
-------------------------------
The thing is that it only goes through the first csv it hits and asks
me if I want to update 1 record. That is fine since that csv only has
1 record, but why didn't it do the rest of the csv's in the folder? I
tried the loop you had in the version you changed to a function but
that wouldn't compile. any suggestions? This is a great sub you put
together.
Thank you.