Solved

Import selected text file records into Access

Posted on 2014-02-24
6
822 Views
Last Modified: 2014-03-26
I need to import into an Access table selected segments of selected data records that are saved in a text file.The text file has a lot of garbage records and data within each record not useful to me that I need to skip over.

In plain English, this is what I need to accomplish:

1. Read the text file from top to bottom
2. If bytes 1 thru 9 = 'Marketing', then import bytes 1 thru 9 of that record into Field1 of the table and bytes 30 thru 40 of the same record into Field2 of the table. Otherwise skip the record.

Thank you.
0
Comment
Question by:dbfromnewjersey
6 Comments
 
LVL 84

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 167 total points
ID: 39883636
Often the best way is to import the file into a temporary or "staging" table, and then perform your data validation using SQL and VBA. Once you've validated the records, you can then move them over to the live tables.

If this is a one-time deal, then you can just use the Access interface to import the Text file.  I'm not sure what sort of table structure you'd end up with - that depends on what sort of file you're working with, and how you import it - but if the first Field of your Staging table is the one that contains the "Market" word, then you could just do this:

Currentdb.Execute("INSERT INTO YourLiveTable(Field1, Field2, Field3) (SELECT Col1, Col2, Col3 FROM YourStagingTable WHERE Col1='Market'")

Of course, how you do this depends entirely on the file structure and such. If you could post an example file, perhaps we could provide more information.
0
 
LVL 34

Assisted Solution

by:PatHartman
PatHartman earned 166 total points
ID: 39883808
All the examples I have are way too complicated to post here.  Look for the syntax for -
Open .... For Input
and
Line Input #FileNum, strLine

To see how to read a text file.

Basically, you have to get a FileNum, Open the file with Open, and then read each record with Line Input.  Beyond that, you're on your own and it depends on the format how you have to process the records.
0
 

Author Comment

by:dbfromnewjersey
ID: 39883868
I'll try to post an example of the type of text files I deal with in a bit.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:dbfromnewjersey
ID: 39883970
By the way, I had already tried importing the file directly into a new Access table for it to act as a staging area for further processing. The problem I had with that method is that in my source file, there is a debit column and a credit column.  When I import the text file, both of those columns wind up being combined into one field in Access instead of staying separate.  I can import the file into Excel first but I wind up having to move the verticle lines around manually in the Text Import Wizard window to get them where I need to be. I'm trying to automate the process as much as possible so that I don't always have to deal with manually moving those lines around before importing.
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 39884050
There is no easy way to import a file with inconsistent row formats which is what it sounds like you have.  If you have debit and credit fields on different rows, your code will need to combine them into one row as you are looping through the import file.
0
 
LVL 31

Accepted Solution

by:
Helen_Feddema earned 167 total points
ID: 39884192
Sometimes you can clean up a file if you import it into Word and use Word's Search and Replace feature to do the cleanup -- then re-save it as a clean text file for import into Access.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now