Article View: comp.databases.ms-access
Article #18Re: How to import multi-line record text file into Access?
From: john hayes
Date: Thu, 07 Jan 1999 00:00
Date: Thu, 07 Jan 1999 00:00
88 lines
3686 bytes
3686 bytes
Rick, Is this Visual Basic code? My client does not have VB - only Access. Any idea how much VB would cost for a Win95 platform? Funding is at a premium for this project.... If possible, I would like to do this with some sort of Access macros or something - but I am not too familiar with Access. Thanks for the input, all! John Hayes aikosys@earthlink.net Rick Stone wrote: > > 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:
<36950860.3D7A@earthlink.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3692698D.AE9@earthlink.net> <3693e598.165513234@news.erols.com> <3694cd52.160243566@news.flash.net>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: john hayes <aikosys@earthlink.net> Subject: Re: How to import multi-line record text file into Access? Date: 1999/01/07 Message-ID: <36950860.3D7A@earthlink.net> X-Deja-AN: 429845564 Content-Transfer-Encoding: 7bit References: <3692698D.AE9@earthlink.net> <3693e598.165513234@news.erols.com> <3694cd52.160243566@news.flash.net> To: Rick Stone <rstone@fenris-inc.com> X-Posted-Path-Was: not-for-mail Content-Type: text/plain; charset=us-ascii X-ELN-Date: 7 Jan 1999 16:17:52 GMT X-ELN-Insert-Date: Thu Jan 7 08:25:06 1999 Organization: EarthLink Network, Inc. Mime-Version: 1.0 Reply-To: aikosys@earthlink.net Newsgroups: comp.databases.ms-access,at.fido.msaccess