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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing data from desktop

Status
Not open for further replies.

SDRichardC

Technical User
Aug 18, 2010
15
US
Can anyone point me into the right direction on how to import data from the desktop.
I know how to import from Access but I am more interested in the code VBA.
I would like to use a command button OnClick function to look for the specific file name and load that data into a table into Access 2007.

Thanks in advance.
 
Have a look at the DoCmd.TransferText method.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Here is what I got and I am running into error where object is required.
The error points to the DoCmd line. Not sure what needs to be there.
The file name that I want to import is PrintQualityData.txt.


Private Sub UpDateDatafromNotepad_Click()

Dim file_name As String
Dim strPath As String
strPath = CurrentProject.Path & "\" & "*.txt"
strFile = Dir(strPath)
file_name = CurrentProject.Path
file_name = "CurrentProject.Path\PrintQualityData.txt"
DoCmd.TransferText acImportDelim, PrintQualityData, tbl_PrintQuality, PrintQualityData.txt

End Sub
 
I just did something like this, but using excel sheets.
I think your problem is just syntax.
If you are always going to be pulling files from the desktop try this.

dim user
dim file
dim fullpath
user = Environ$("username")
file = "myfile.txt"
fullpath = "C:\Users\" & user & "\Desktop\" & file
DoCmd.TransferText acImportDelim, PrintQualityData, "tbl_PrintQuality", fullpath

 
Thanks dan08, it works well, though it keeps telling me that there is no F1 field in the table. Until I put an F1 field it works but
completely puts that data into just that one field and seperated by rows.

I have already made the field names in the table and would want it to insert those data belonging to the specified fields.
Thank you again.
 
If I'm not mistaken "PrintQualityData" is an import process you have defined. The error might stem from there.
 
dan08

I have inserted True after fullpath and it works great.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top