Article View: comp.databases.ms-access
Article #17Re: How to import multi-line record text file into Access?
From: Rick Stone
Date: Thu, 07 Jan 1999 00:00
Date: Thu, 07 Jan 1999 00:00
76 lines
3024 bytes
3024 bytes
I have a routine that will import this. You need to open the text
file and read it line by line, then append the line to your database.
Here's my basic function:
Function ImportFile()
Dim intImportFile As Integer
Dim strImportFile As String
Dim strTableName As String
Dim strInputLine As String
Dim dbs As Database
Dim rst As Recordset
strImportFile = "c:\temp\temp.txt"
strTableName = "TempTable"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strTableName, dbOpenDynaset)
intImportFile = FreeFile
Open strImportFile For Input As #intImportFile
Do Until EOF(intImportFile)
Line Input #intImportFile, strInputLine
rst.AddNew
rst!Line1 = strInputLine
Line Input #intImportFile, strInputLine
rst!Line2 = strInputLine
rst.Update
Loop
Close intImportFile
End Function
You need to add error checking when you're doing the Line Input
statements and test with your file to see if there are any extra lines
at the end. Also, if there's a blank line between records, you need
to do an extra Line Input statement to get rid of that.
The table "TempTable" has two fields, "Line1" and "Line2".
If you have any questions, please respond.
>On Tue, 05 Jan 1999 11:35:41 -0800, john hayes <aikosys@earthlink.net>
>wrote:
>
>>I need to import a text data file which has 2 lines per record, into
>>Access. I have tried the Import Wizard, but it does not seem to support
>>multi-line records. I see that you can save/load a format spec
>>for a file, but I didn't see if it saves the spec in a file that
>>I can manipulate (or create from scratch) - it seems to save the spec
>>internally? Also, I don't know the syntax requirements for such a
>>spec file (not in the book).
>>
>>Can anyone tell me how to tell Access that it needs to load multi-line
>>records from a text file? BTW - editing the text file to make single-
>>line records is not an option, since the data file is created that
>>way by a canned vendor module and will have to be loaded periodically
>>on-going.
>>
>>Also, is there a way to import without going through the Wizard?
>>
>>Thanks!
>>
>>John Hayes
>>aikosys@earthlink.net
>>
>
Richard L. Stone
Healthcare-ID
rstone@fenris-inc.com
Technical Details
Message-ID:
<3694cd52.160243566@news.flash.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3692698D.AE9@earthlink.net> <3693e598.165513234@news.erols.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: ff0ac,36002617d1beb0ca X-Google-Attributes: gidff0ac,public X-Google-Thread: 1668c5,36002617d1beb0ca X-Google-Attributes: gid1668c5,public From: rstone@fenris-inc.com (Rick Stone) Subject: Re: How to import multi-line record text file into Access? Date: 1999/01/07 Message-ID: <3694cd52.160243566@news.flash.net> X-Deja-AN: 429819507 References: <3692698D.AE9@earthlink.net> <3693e598.165513234@news.erols.com> X-Complaints-To: abuse@flash.net X-Trace: news.flash.net 915722323 208.194.201.178 (Thu, 07 Jan 1999 09:18:43 CDT) Organization: FlashNet Communications, http://www.flash.net NNTP-Posting-Date: Thu, 07 Jan 1999 09:18:43 CDT Newsgroups: comp.databases.ms-access,at.fido.msaccess