473,791 Members | 3,098 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

4 New Member
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 3014
janders468
112 Recognized Expert New Member
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
diasdaman
4 New Member
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,579 Recognized Expert Moderator MVP
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
diasdaman
4 New Member
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,579 Recognized Expert Moderator MVP
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 Recognized Expert New Member
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,579 Recognized Expert Moderator MVP
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
diasdaman
4 New Member
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
11366
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 exactly cause I'm not familar with paradox at all, but I've found files like *.db, *.mb, *.px, *.xg*, *.yg* !!! I need the infomation from this files to combine it with other data stored in SQL 2000. I'm tried DTS to import the Data but I've got an...
1
7551
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 automated fashion. I am not really concerned about how many tables it requires or what the schema looks like as long as the data remains related and ends up in its respective fields (I will probably use scratch tables for this). The data is given...
1
5916
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 table within SQL Server. This import needs to run continuously, as more text files will be saved in the folder by a separate system and they need to be updated into the SQL Server table. I have a DTS which can import all text files from the...
1
8184
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 fields. 177 102003 16:43:12 102003 18:43:12 6OAG0ADP Y 0000 0000 0000 0000 61930 4HGA800 165 102003 17:43:12 102003 18:44:12 6OAG0ADP Y 0000 0000 0000 0000 61930 4HGA800 177 102003 16:41:18 102003 18:45:12 6OAG0ADP Y 0000 0000 0000 0000 61930...
1
6703
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 database stats: Path: C:\Database (contains the database and all the text files to be imported) Text files to import: (SampleData4.txt and SampleData3.txt as testing examples)
6
3054
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 newsgroup forum, so this fact was fixed. Since I have to transfer files from VMS( SAS ) to WIN (Access), I still keep using ACC97 as a simplest and reliable tool. However, final products, such as distributable data entry system for multi central...
1
4185
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 data import, the list of files to import does not include text files of any type, only other database formats. On a 102,000 line text file, I was able to split it with Word 97, import the split files into Excel 97 one at a time, and then save...
1
2688
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 issue. But ... Office 2000 was on this machine when it was given to me. I don't own it. After installing Office 97, mine, in a different directory, and checking most of it out, I uninstalled Office 2000. Well, it's a lot easier to upgrade than...
6
26332
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 one table. My problem is I have two buttons I want to use this code for for the two buttons would put the data in different tables. I have tried copying and changing a few things and nothing will work for me. The code is set up in a module and then I...
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10207
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10155
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5431
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.