Hello,
I'm looking to see if someone can tell me how to write a module that
will import csv files into a table.
The file names ALL have the word containing TRKR and they are labeled
differently.
Currently, I download csv, save in a folder, prep csv files for
manually importing into access.
Any suggestions?
Thanks Simplymidori
Tom Wickerath - 31 Mar 2007 09:38 GMT
Hi Simplymidori,
Use the TransferText method. Here is an example:
Private Sub cmdImportCSVTextFile_Click()
On Error GoTo ProcError
DoCmd.TransferText _
TransferType:=acImportDelim,
SpecificationName:="CompanyDelimited", _
Tablename:="YourTableNameHere", _
Filename:="CompletePathToYourFile.txt", _
HasFieldNames:=True
MsgBox "Company details imported from a" & vbCrLf _
& "comma separated value (CSV) text file"
ExitProc:
Exit Sub
ProcError:
MsgBox "Error: " & Err.Number & ". " & Err.Description
Resume ExitProc
End Sub
For simplicity, I'm showing a hard-coded path above for the FileName
parameter. There are various ways of supplying the complete file path
dynamically. One method involves a little API code to invoke the Common File
Dialog. If all of your files were in one directory, you could set up a loop
and use the Dir function to determine the complete path of each file.
Tom Wickerath
Microsoft Access MVP
http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
> Hello,
>
[quoted text clipped - 10 lines]
>
> Thanks Simplymidori
Tom Wickerath - 31 Mar 2007 09:40 GMT
Hi Simplymidori,
Use the TransferText method. Here is an example:
Private Sub cmdImportCSVTextFile_Click()
On Error GoTo ProcError
DoCmd.TransferText _
TransferType:=acImportDelim,
SpecificationName:="CompanyDelimited", _
Tablename:="YourTableNameHere", _
Filename:="CompletePathToYourFile.txt", _
HasFieldNames:=True
MsgBox "Company details imported from a" & vbCrLf _
& "comma separated value (CSV) text file"
ExitProc:
Exit Sub
ProcError:
MsgBox "Error: " & Err.Number & ". " & Err.Description
Resume ExitProc
End Sub
For simplicity, I'm showing a hard-coded path above for the FileName
parameter. There are various ways of supplying the complete file path
dynamically. One method involves a little API code to invoke the Common File
Dialog. If all of your files were in one directory, you could set up a loop
and use the Dir function to determine the complete path of each file.
Tom Wickerath
Microsoft Access MVP
http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
> Hello,
>
[quoted text clipped - 10 lines]
>
> Thanks Simplymidori
Tom Wickerath - 31 Mar 2007 09:40 GMT
Hi Simplymidori,
Use the TransferText method. Here is an example:
Private Sub cmdImportCSVTextFile_Click()
On Error GoTo ProcError
DoCmd.TransferText _
TransferType:=acImportDelim,
SpecificationName:="CompanyDelimited", _
Tablename:="YourTableNameHere", _
Filename:="CompletePathToYourFile.txt", _
HasFieldNames:=True
MsgBox "Company details imported from a" & vbCrLf _
& "comma separated value (CSV) text file"
ExitProc:
Exit Sub
ProcError:
MsgBox "Error: " & Err.Number & ". " & Err.Description
Resume ExitProc
End Sub
For simplicity, I'm showing a hard-coded path above for the FileName
parameter. There are various ways of supplying the complete file path
dynamically. One method involves a little API code to invoke the Common File
Dialog. If all of your files were in one directory, you could set up a loop
and use the Dir function to determine the complete path of each file.
Tom Wickerath
Microsoft Access MVP
http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
> Hello,
>
[quoted text clipped - 10 lines]
>
> Thanks Simplymidori