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

Import Delimited File 1

Status
Not open for further replies.

SeaRay

Technical User
Jan 8, 2002
20
US
I am trying to automate a process of importing a comma seperated delimited file into access. Also, I am trying to start on the forth row. I saw this posting for a similar question, but need a little more specific explanation {is "SpecName" the name I give to the saved procedure? table name where I want the data to end up? "filename" the file that I am importing? is full path refering to the full path of the delimted file location?), as well as if I can start on the forth row. Thanks, Rick

You must first import the file once manually with the import wizard.
When you get to the last window of the wizard, you must click the "advanced" button and then "save as" and give the import specification a name.
Then you create an event procedure for your button. Type the command
sub button1_onclick

docmd.TransferText acImportDelim,"SpecName","tablename","filename" = full path

end sub
 
The example TransferText you show is illustrative, not syntactically correct. The syntax is:
Code:
    docmd.TransferText acImportDelim, _
      [i]SpecName[/i], [i]TableName[/i], [i]FileName[/i]
SpecName is the name of the import specification, the name you entered in the Advanced dialog of the Import Wizard when you saved the import spec. TableName is the name of the table into which the records will be inserted. FileName is the file name of the text file. You should include the full path name, unless you know the file is in the "current" directory. All three parameters can be a string literal or a variable.

I'm afraid there's no way to skip the first three rows with the TransferText method. If it were only one row, you could skip it by setting the HasFieldNames parameter (not shown in the example) to True, but with three rows it won't help.

To eliminate the first three rows, I'd suggest writing code to copy the file to a temporary file (dropping the unwanted lines), then import that. You'll need to use the Open, Close, Line Input, and Print # statements. You may also have to invent an obscure temporary file name, to ensure that you don't accidentally overwrite an existing file.
Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top