Import Text File (1 Viewer)

fhs

Registered User.
Local time
Today, 04:38
Joined
Aug 8, 2001
Messages
68
Is this the correct code to access and upload a text file from the desktop to the Inventory table in the NEW Inventory Scanner DB file in the Inventory folder on the J: drive? I keep getting a “this isn’t a valid path” violation. Whatsamatter?

DoCmd.TransferText acImportDelim, "Invent Import Specification", "Invent", "J:\Inventory\NEW Inventory Scanner DB\Inventory"
'Import daily Inventory file

Thanx...
 

modest

Registered User.
Local time
Yesterday, 23:38
Joined
Jan 4, 2005
Messages
1,220
Code:
strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.txt")
strFile = ahtCommonFileOpenSave(InitialDir:=CurrentDb.Name, Filter:=strFilter, OpenFile:=True, DialogTitle:="Title of Window Goes Here")
    
If strFile = "" Then Exit Sub
    
DoCmd.TransferText acImportDelim, "Specification Name", "Table Name", strFile, False

This is the code I use to open a file using a dialog window. However if you didn't want to use a window and just keep it static in your code, just replace the "strFile" with the full location of your file, much like you have done, but include the "\filename.txt" too.

Additionally you're importing to table "Invent" you may want to check the name of your table and make sure it's not "Inventory"

-modest



PS to use the filter and the dialog insert the attached file as a module of your database, courtesy of Ken Getz.
 

Attachments

  • Module.txt
    8.8 KB · Views: 131

Users who are viewing this thread

Top Bottom