Article View: comp.databases.ms-access
Article #20Re: How to import multi-line record text file into Access?
From: Rick Stone
Date: Fri, 08 Jan 1999 00:00
Date: Fri, 08 Jan 1999 00:00
103 lines
4148 bytes
4148 bytes
As people have said, put the code in a module in Access and it will work just fine. You will have to modify it to work with your particular tables and files. If you haven't worked with modules, you'll have some learning to do. I don't think you can do what you want with a macro. On Thu, 07 Jan 1999 11:17:52 -0800, john hayes <aikosys@earthlink.net> wrote: >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 > Richard L. Stone Healthcare-ID rstone@fenris-inc.com
Technical Details
Message-ID:
<36963b0d.253884644@news.flash.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3692698D.AE9@earthlink.net> <3693e598.165513234@news.erols.com> <3694cd52.160243566@news.flash.net> <36950860.3D7A@earthlink.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: rstone@fenris-inc.com (Rick Stone) Subject: Re: How to import multi-line record text file into Access? Date: 1999/01/08 Message-ID: <36963b0d.253884644@news.flash.net> X-Deja-AN: 430240847 References: <3692698D.AE9@earthlink.net> <3693e598.165513234@news.erols.com> <3694cd52.160243566@news.flash.net> <36950860.3D7A@earthlink.net> X-Complaints-To: abuse@flash.net X-Trace: news.flash.net 915815255 208.194.201.79 (Fri, 08 Jan 1999 11:07:35 CDT) Organization: FlashNet Communications, http://www.flash.net NNTP-Posting-Date: Fri, 08 Jan 1999 11:07:35 CDT Newsgroups: comp.databases.ms-access,at.fido.msaccess