ChiTownDiva
Technical User
Murnin' All...Happy Hump Day...
Last week I posed the question:
"I wonder if Access can:
1. In a windows folder, change the file extension from DAT to TXT (or CSV).
2. Use an import spec and import the file into the database.
3. Append the file to an existing table.
4. Drop the imported file from the database.
I need to figure out a way to do this via some code because I have about 100 tables to import into a database this way."
I got a pretty good answer:
Function Import()
With Application.FileSearch
.NewSearch
.LookIn = "S:\SALESUP\Yasu\test"
.SearchSubFolders = True
.FileName = "*.TXT"
.MatchTextExactly = True
End With
With Application.FileSearch
If .Execute() > 0 Then
For I = 1 To .FoundFiles.Count
DoCmd.TransferText acImportDelim, "VALUE Import Specs", "TempTable", .FoundFiles(I), True
DoCmd.OpenQuery "testappendquery"
Next I
End If
End With
End Function
Well, now we want to be able to download all of the *.dat files without going in manually changing each one to a *.txt file first. Also we don't want to append each import to a table. We just want to import each download as a table.
I know I can change the extension via MS DOS, but I don't have those privledges. The alternative is to accomplish this via Access. I know there is a GetFile() function in Access. Is there a way to incorporate this function within the above code so we don't have to change all of our *.dat files to *.txt files first and then simply import each download into the database?
Thanks in advance for any assistance with this.
ChiTownDiva![[ponytails2] [ponytails2] [ponytails2]](/data/assets/smilies/ponytails2.gif)
Last week I posed the question:
"I wonder if Access can:
1. In a windows folder, change the file extension from DAT to TXT (or CSV).
2. Use an import spec and import the file into the database.
3. Append the file to an existing table.
4. Drop the imported file from the database.
I need to figure out a way to do this via some code because I have about 100 tables to import into a database this way."
I got a pretty good answer:
Function Import()
With Application.FileSearch
.NewSearch
.LookIn = "S:\SALESUP\Yasu\test"
.SearchSubFolders = True
.FileName = "*.TXT"
.MatchTextExactly = True
End With
With Application.FileSearch
If .Execute() > 0 Then
For I = 1 To .FoundFiles.Count
DoCmd.TransferText acImportDelim, "VALUE Import Specs", "TempTable", .FoundFiles(I), True
DoCmd.OpenQuery "testappendquery"
Next I
End If
End With
End Function
Well, now we want to be able to download all of the *.dat files without going in manually changing each one to a *.txt file first. Also we don't want to append each import to a table. We just want to import each download as a table.
I know I can change the extension via MS DOS, but I don't have those privledges. The alternative is to accomplish this via Access. I know there is a GetFile() function in Access. Is there a way to incorporate this function within the above code so we don't have to change all of our *.dat files to *.txt files first and then simply import each download into the database?
Thanks in advance for any assistance with this.
ChiTownDiva
![[ponytails2] [ponytails2] [ponytails2]](/data/assets/smilies/ponytails2.gif)