473,394 Members | 1,734 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,394 software developers and data experts.

Remove text file header

I'm creating a database that will be uploading some text files into an
access table. The problem is that the text files have a header which
messes up my import specs. so what i have had to do is to open the
files and manually delete the data before importing them. Is there a
way i can programatically do this? ie programmatically edit the text
file and remove the surplus header text, and then import the file with
the DoCmd.TransferText function?

Below is a sample of the data that iam working with: The stuff that i
want deleted is between the "Å"
Å



*************************************************
ViewDirect *************************************************
*************************************************
ViewDirect *************************************************

**
**
** RECIPIENT: U703287 CLIFF
KING **
** USER-ID: U703287 Long
Beach **
** Accounts
Payable **

**
**

**
**

**
**

**
**
** REPORT ID: s123q31 BATCH REPORT
TOTALS **

**
**
** VERSION: 20070430
021155
**

**
**
** FROM HIERARCHY CODE:
FROM PAGE: 000001 **

**
**
** TO HIERARCHY CODE:
TO PAGE: @LAST **

**
**
** PAGE OUTPUT LIMIT:
000100
**

**
**

************************************************** ************************************************** **********

************************************************** ************************************************** **********

DATE:
06/05/2007
TIME:
14:11.51
Å
123 Long Beach COMPA PRJ/RPT P31 PAYMENT SYSTEM THE CO. DATE
04/30/07 TIME 01.58 WK13/PD04 PAGE 1

RPT VPSI601.I708 BATCH SUMMARY
REPORT FORWARD TO: ACCOUNTING -
ACCOUNTS PAYABLE
BATCH REFERENCE NUMBER : A77_41


Thanks

Jun 5 '07 #1
2 6561
Greetings,

Here is a programmatic approach to your problem (note: I steer away
from Import and Spec - this is much more reliable and efficient)
Sub ReadFile()
Dim DB As DAO.Database, RS As DAO.Recordset
Dim RS2 As DAO.Recordset
Dim str1 As String, str2() As String, i As Integer

DoCmd.SetWarnings False
DoCmd.RunSQL "Delete * From tblA1"
DoCmd.RunSQL "Delete * From tblA"
Set DB = CurrentDb
Set RS = DB.OpenRecordset("tblA1")

Close #1
Open "C:\1A\testRead.txt" For Input As #1
i = 0
Do While Not EOF(1)
Line Input #1, str1
If i 1 Then
RS.AddNew
RS(0) = str1
RS.Update
End If
i = i + 1
Loop
Close #1

RS.MoveFirst
Set RS2 = DB.OpenRecordset("tblA")
Do While Not RS.EOF
str2 = Split(RS(0), "|")
RS2.AddNew
For i = 0 To UBound(str2) : RS2(i) = str2(i) : Next
RS2.Update
RS.MoveNext
Loop
DoCmd.SetWarnings True
End Sub

I create a test text file called textRead.txt and loaded it as follows:

Test File <-----this is the header line you don't want

Dick|Jane|Paul
Sue|Mary|Sam
Tom|June|May
Sun|Mun|Dun

I am using the Open method of VBA for reading text from textfiles. I
use the Line Input method to read each line as one string. Then I use
DAO code to write that line to tblA1 which contains only one field -
depending on the size of your data, I made this field a text field of
size 100. If you have more than 255 chars per line, you can make the
field a memo field and will work just fine. After I read the contents
of the textfile to tblA1, I loop through that table and parse out the
data - note that I use | pipe symbol as my delimeter. Now I can use the
string "Split" function to parse each line into a string array. Then I
read the contents of the array into tblA. Now I have parsed out my data
and omitted the dreadful Header line by counting 2 rows from the
textfile before I begin reading the data.

There is plenty of documentation in the help files on reading data from
text files. Just copy this code into a Standard code module and place
the mouse cursor of any object you have a question about and press the
F1 key and help will come up on that object.
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jun 5 '07 #2
File I/O statements have been around since the olden days of Basic, and it's
not awfully difficult to Open the file, skip the extraneous information, and
then write a new file, which you use for the import.

Larry Linson
Microsoft Access MVP

<Cl*****@gmail.comwrote in message
news:11**********************@o5g2000hsb.googlegro ups.com...
I'm creating a database that will be uploading some text files into an
access table. The problem is that the text files have a header which
messes up my import specs. so what i have had to do is to open the
files and manually delete the data before importing them. Is there a
way i can programatically do this? ie programmatically edit the text
file and remove the surplus header text, and then import the file with
the DoCmd.TransferText function?

Below is a sample of the data that iam working with: The stuff that i
want deleted is between the "Å"
Å



*************************************************
ViewDirect *************************************************
*************************************************
ViewDirect *************************************************

**
**
** RECIPIENT: U703287 CLIFF
KING **
** USER-ID: U703287 Long
Beach **
** Accounts
Payable **

**
**

**
**

**
**

**
**
** REPORT ID: s123q31 BATCH REPORT
TOTALS **

**
**
** VERSION: 20070430
021155
**

**
**
** FROM HIERARCHY CODE:
FROM PAGE: 000001 **

**
**
** TO HIERARCHY CODE:
TO PAGE: @LAST **

**
**
** PAGE OUTPUT LIMIT:
000100
**

**
**

************************************************** ************************************************** **********

************************************************** ************************************************** **********

DATE:
06/05/2007
TIME:
14:11.51
Å
123 Long Beach COMPA PRJ/RPT P31 PAYMENT SYSTEM THE CO. DATE
04/30/07 TIME 01.58 WK13/PD04 PAGE 1

RPT VPSI601.I708 BATCH SUMMARY
REPORT FORWARD TO: ACCOUNTING -
ACCOUNTS PAYABLE
BATCH REFERENCE NUMBER : A77_41


Thanks
Jun 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Michael | last post by:
I have a data application in a2k that I need to create two fixed width text files and then combine them to a single file The first file is header information and the second is transaction data. ...
5
by: Johnny Meredith | last post by:
I have seven huge fixed width text file that I need to import to Access. They contain headers, subtotals, etc. that are not needed. There is also some corrupt data that we know about and can...
11
by: MM | last post by:
Hi I have never written any C programs before, but it seems that I need to do so now. Hope some of you out there can spend a few minutes and help me by writing a simple example of something...
7
by: Robert Adkison | last post by:
I need to print a web page. It is my preference that my users just do a File/Print from explorer. That way my users will get the print dialog that will allow them to select the fax printer. The...
3
by: Christian Lutz | last post by:
Hy there I have a Web Services written in Java, running on Tomcat. The Client is written in C#. When i monitor the request/Response with TCPMon (included in Tomcat) i can observer the following...
31
by: Extremest | last post by:
I have a loop that is set to run as long as the arraylist is > 0. at the beginning of this loop I grab the first object and then remove it. I then go into another loop that checks to see if there...
31
by: smachin1000 | last post by:
Hi All, Does anyone know of a tool that can automatically analyze C source to remove unused #includes? Thanks, Sean
0
by: guilho | last post by:
Hi all! I'm newbie on php. On the web site i'm developing, i have encoutered a problem that i can't resolve. I have a script that makes the file upload, and then, based on the upload, it displays...
6
by: Romulo NF | last post by:
Greetings again to everyone, Im back to show this grid componenet i´ve developed. With this grid you can show the data like a normal table, remove the rows that you need, add rows, import data,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.