473,396 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How do I import a text file into Microsoft Access 2000... into different tables?

I know how to import text files, but in this case I need to import a text file line by line on an on-the-fly basis, such that the Access will look at the first two digits of a line, and then import the rest of the line based on a given specification into an appropriate table.

I'm not that familiar with VBA, but I can pick it up if I need to. But first I want to know if what I want to do is even possible.
Jul 31 '08 #1
8 2985
janders468
112 Expert 100+
I've had to do this before and there are certainly many ways to do it so this may not be the best. There are really two routes I see with this both will require some coding however. One is to parse the lines of text yourself using code, and two is to separate out the file(s) (based on the two digit code that indicates the record structure) into temporary text files and use predefined import specifications. It probably depends on the volume of data you have. The import specs are going to be faster than writing your own parsing mechanism but it also requires a lot more overhead to maintain separate files and then delete them. It also depends on how automated it needs to be, for instance it would be very easy to write code that takes a text file or set of text files and separates them out into text files with like records and then go back and manually load those, it will be much more elaborate to say, do everything from a click of a button. Let me know what you think of those ideas and we can start walking through code to do it. If you would like.
Aug 3 '08 #2
I've had to do this before and there are certainly many ways to do it so this may not be the best. There are really two routes I see with this both will require some coding however. One is to parse the lines of text yourself using code, and two is to separate out the file(s) (based on the two digit code that indicates the record structure) into temporary text files and use predefined import specifications. It probably depends on the volume of data you have. The import specs are going to be faster than writing your own parsing mechanism but it also requires a lot more overhead to maintain separate files and then delete them. It also depends on how automated it needs to be, for instance it would be very easy to write code that takes a text file or set of text files and separates them out into text files with like records and then go back and manually load those, it will be much more elaborate to say, do everything from a click of a button. Let me know what you think of those ideas and we can start walking through code to do it. If you would like.
I suppose I'd prefer the click of a button approach, but I'm not dealing with massive amounts of information. I think a typical file might have 120 records, but they go into maybe 10 different tables at the most. So as long as everything can be contained in a folder and deleted promptly, I think my client would be ok with manually loading them.

Just a word about my skill level: I know how to create specifications and macros to use them, and I know how to write the necessary code in other languages (PHP being my most proficient), but not in VBA.

Thanks so much for any help.
Aug 4 '08 #3
NeoPa
32,556 Expert Mod 16PB
Import the file into a single temporary table (after clearing any previous data from the table of course).

Depending on your specific requirements (unspecified for some reason) run queries that select specific records to be appended to each table where you want the data to end up.

This can be as sophisticated or simple as you're comfortable with.
Aug 5 '08 #4
Import the file into a single temporary table (after clearing any previous data from the table of course).

Depending on your specific requirements (unspecified for some reason) run queries that select specific records to be appended to each table where you want the data to end up.

This can be as sophisticated or simple as you're comfortable with.
Well, as I mentioned, different records have different specifications (field structures). If they all had the same fields and could therefore be imported into one table, then I don't see what the point of moving them to different tables would be.

Perhaps the only thing I may have left out is that I'm dealing with fixed width data, not delimited. However, each row / record in the text file has a different structure.
Aug 6 '08 #5
NeoPa
32,556 Expert Mod 16PB
Well, as I mentioned, different records have different specifications (field structures). If they all had the same fields and could therefore be imported into one table, then I don't see what the point of moving them to different tables would be.
It might be interesting for you to show where that was mentioned. It's certainly not visible in this thread.

Regardless of that blatant inaccuracy, if I approached each problem by trying to guess WHY a poster asked a question every time, I would have little more sanity left than ... well I won't go on.
Perhaps the only thing I may have left out is that I'm dealing with fixed width data, not delimited. However, each row / record in the text file has a different structure.
Yes - that was another of the (quite important) points you forget to mention.

Anyway, to clarify things somewhat I'll explain in long-hand.

You cannot do a bulk-import into separate tables depending on the contents of the data.

You have two choices as far as I can see (and which you decide to choose depends heavily on information you have, but which has not yet been shared in this thread) :
  1. Parse the files outside of Access (possibly using Access VBA but there's nothing to recommend that above any other means of processing raw files), somehow sorting them into different files depending on your actual requirements. Load them into Access tables from the separated files.
  2. Bulk load all the lines into an Access table. The layout of this table would obviously have to be non-specific enough to handle any data that is likely to appear (If this means specifying a table containing a single long text field then so be it). Using SQL APPEND queries, or even Recordset processing VBA code if you prefer, apply the data, suitably re-created from the basic text, into the relevant eventual tables.
Aug 6 '08 #6
janders468
112 Expert 100+
Hi diasdaman I've been swamped at work so slow in coming on the code I wrote this code up as a way to separate the files into different files based on the leading two characters of each line:
Expand|Select|Wrap|Line Numbers
  1. Sub CategorizeByCriteria(Criteria As String, FileFrom As String, FileTo As String)
  2.     Dim intFileOne As Integer, intFileTwo As Integer, lngCounter As Long
  3.     Dim strBuffer As String
  4.     Dim strRecords() As String
  5.     intFileOne = FreeFile
  6.     Open FileFrom For Input As #intFileOne
  7.     intFileTwo = FreeFile
  8.     Open FileTo For Append As #intFileTwo
  9.     strBuffer = Input(LOF(intFileOne), #intFileOne)
  10.     strRecords = Split(strBuffer, vbCrLf)
  11.     For lngCounter = LBound(strRecords) To UBound(strRecords)
  12.         If Mid(strRecords(lngCounter), 1, 2) = Criteria Then
  13.             Print #intFileTwo, strRecords(lngCounter)
  14.         End If
  15.     Next lngCounter
  16.     Close intFileOne
  17.     Close intFileTwo
  18. End Sub
  19.  
You would then call this like the following:
Expand|Select|Wrap|Line Numbers
  1. CategorizeByCriteria "01","C:/largefile.txt","c:/newfile.txt"
  2.  
This would put every record that begins with "01" from "c:/Largefile.txt" in "c:/newfile.txt" It will create the file if it does not exist. You can then use predefined import specs to import the different files. Let me know about any code solutions (such as importing each of these files) you would like to see. I don't want to paste more than necessary because I have a tendency to get very lost when code goes on and on, and assume that it wouldn't be too helpful at this point. The other thing I should mention is that this assumes that each record is on its own line, or that you want to view them on a line by line basis.
Aug 6 '08 #7
NeoPa
32,556 Expert Mod 16PB
Janders468's suggestion would fall into category 1.

As he's been so helpful I would urge you to snap him up (thankfully) on his offer. Not everyone will be prepared to go to so much trouble on a single question.

PS @Janders468 - Nice work and helpful attitude :)

PPS You would need to call the procedure for each file you wanted created.
Aug 6 '08 #8
Janders468,

Thank you very much. That looks like exactly what I needed, and I think I know exactly what to do from here.
Aug 6 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: TonyMontana | last post by:
Hello, I've the following problem. I've to read out the data of a custom application. I think (I'm not sure) this application is using a Paradox DB to store it's information. I don't know it...
1
by: Sven | last post by:
Hello, I am receiving a text file that is produced from a mainframe that is out of my control. I am attempting to find a (hopefully clean) way to import it into a SQL Server database in an...
1
by: Chris | last post by:
Background: I am using a MS Access 2000 front end with SQL Server 8.0 back end. I have the requirement to import all text files (regardless of filename) from a given folder on the network into a...
1
by: mark | last post by:
In Access 2000 and 2002, I have created an import specification to import the fixed-width recordset below into an existing table. I am having strange problems with the import of the date and time...
1
by: Dan | last post by:
Could someone please help me with auto importing a series of data files into an Access table. I tried to follow code given below in a previous messagebut i'm getting error messages. Here's my...
6
by: Vladislav Moltchanov | last post by:
I have discovered a couple of years ago, that import with DoCMD.TransferText for CSV text file doesn’t work in Acc2000, while it works perfectly in ACC97. which has been discussed on this...
1
by: Child of His | last post by:
I have been through every trick I know, or has been suggested. I have a one to two million line fixed field database in text format. I want to bring it into Access 97. When I use the external...
1
by: Wandering | last post by:
I know you guys are heavy duty coders, while I do ad-hoc analysis, and rarely write code. And, I may be in the wrong groups because this is about an install issue, and I don't think it's a code...
6
by: provor | last post by:
Hello, I have the following code that I am using when a user presses a button to import an excel file into a table. The code is hard coded to point to the correct table. This works great for this...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.