Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import Files with Command Button

Status
Not open for further replies.

netrusher

Technical User
Feb 13, 2005
952
US
Can anyone tell me how to import a .csv or .txt file into an existing Access table by using a command button? I have exported a file before that was already in Access. Now I have two files one is a .csv and the other is a .txt file. I manually imported them but I want to be able to update the two tables with fresh data and not link the .csv and .txt files. I have a delete query that removes the old data from the table and I would love to be able to import the refreshed data into the existing tables by just clicking a command button. Thanks for any help!
 
Have a look at the DoCmd.TransferText method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I have looked and searched and do not understand how do accomplish what I am trying to do. Can anyone be a little more specific on how to import a .csv file into a new Table. The file location is at:
S:\Eng\SPED Tracking\TABLES\MRP.csv

I want to be able to click a command button to automatically import this file into a new table or overwrite and existing table.

Thanks for any help!
 
As PHV suggested, this should do... put this code behind your command button to import. First line should read something like:

Private Sub cmdImport_Click()

Code:
Dim strTBLname As String
Dim strFileLoc As String

'your table name here
strTBLname = "MRP"
'your import path here
strFileLoc = "S:\Eng\SPED Tracking\Tables\MRP.csv"

If FileExist(strFileLoc) Then
    DoCmd.TransferText acImportDelim, , strTBLname, strFileLoc
     Else
    MsgBox strFileLoc & " was not found.", vbInformation, "Import"
End If

End Sub


~Melagan
______
"It's never too late to become what you might have been.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top