Automated Importing CSV into Access - NO LINKS

S

simplymidori

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
 
G

Guest

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
__________________________________________
 
G

Guest

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
__________________________________________
 
G

Guest

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
__________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top