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

Input multiple line text file into one access record

Hello Everybody,
Being new to VBA for Access, I have a question about inputing a text
file into access. The text file has 23 lines per file and needs to go
into 1 record in a table. The 1st four lines are garbage and don't need

to be inputted. THe rest of the lines only need what is after an equal
sign (=) inputted. Can somebody please help me?
THanks

Nov 13 '05 #1
4 5170
Could you show enough of the file so we have some clue what you're
dealing with, and/or could you describe it?

If the fields in the text file are delimited then you should be OK.
Maybe you can import to a temporary table and delete the first four
records and then go from there, but this sounds like something you may
need to read in code and append to a table.

Nov 13 '05 #2
From: MM
Sent: Wednesday, August 17, 2005 2:56 PM
To: gr**************@thank.org
Subject: Grant Application
Social Security # = 412345678
Branch of Service = Air Force
Last Name = Jones
Rank - First Name = Robert
Initial = J
Mailing Address = 1122 Boogie Woogie
City = new prague
State = GA
Zip = 12345

First 4 lines not needed and then everything after equal sign goes into
a field in a single record.

Nov 13 '05 #3
Here's the code... watch the wrap. I'm just about sure this can be
done more nicely with ADO and textstreams, but I haven't a clue how to
do this... so here it is using line reading stuff... <try not to laugh>

Private Sub Command0_Click()
Dim db As DAO.Database
Dim rsDest As DAO.Recordset

Dim intInputFile As Integer
Dim strLineIn As String
Dim strFileToImport As String
Dim intCounter As Integer
'---stores the location of the equals sign
Dim strText As String
Dim intFindDelim As Integer
'--get the file from the user
'--NOTE: This line requires the OpenSaveFile API from here:
'http://www.mvps.org/access/api/api0001.htm

strFileToImport = TestIt
intInputFile = FreeFile
Open strFileToImport For Input As intInputFile

'--open the file for reading, skipping the first four lines
For intCounter = 1 To 4
'--read, but do not process lines 1-4
Line Input #intInputFile, strLineIn
Next intCounter
'--open the recordset so we can add records to it.
Set db = DBEngine.Workspaces(0).Databases(0)
Set rsDest = db.OpenRecordset("tblSoldier", dbOpenTable)
'-reset counter to zero (to correspond to zero-based fields
collection of the tabledef/recordset
rsDest.AddNew
intCounter = 0

'--read the rest of the file. Basic idea is that intFieldNo
(zero-based) = the sort of offset of the value
'--IOW, if you loop through a counter, the counter= 0 at 5 (line
1). then these will match the field offsets
'--in the table.

'-- Branch of Service = Air Force
'-- Last Name = Jones
'-- Rank - First Name = Robert

Do Until EOF(intInputFile)
Line Input #intInputFile, strLineIn
'strLineIn needs to be parsed a little - strip off the junk
intFindDelim = InStr(1, strLineIn, "=", vbTextCompare)
If intFindDelim = 0 Then Exit Do
'--trim off the junk
strText = Trim$(Right$(strLineIn, Len(strLineIn) -
intFindDelim))

'--write the field to the record
rsDest.Fields(intCounter) = strText
intCounter = intCounter + 1
Loop

'--we should have all the fields now, so save the record
rsDest.Update

rsDest.Close
Set rsDest = Nothing
Set db = Nothing

MsgBox "done"

End Sub

Nov 13 '05 #4
Thanks - it worked great

Nov 13 '05 #5

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

Similar topics

4
by: googlinggoogler | last post by:
Hiya, The title says it all really, but im a newbie to python sort of. I can read in files and write files no probs. But what I want to do is read in a couple of files and output them to one...
5
by: Gregg | last post by:
Hello all, I have been banging my head over a problem that I am having reading a comma seperated file (CSV) that can contain from 1 to 10,000 records. My code snipit is as follows: **Start...
1
by: ccr | last post by:
Reposted with a longer line length. Apologies if I did not cancel the 1st attempt before you got it. If necessary, please view in a text editor so the columnar text lines up. I used Terminal...
12
by: Wadim Grasza | last post by:
I want to store and display (on a form or a report) multiple pictures per record in an access database. The pictures are not stored within the database. They are stored as files and the database...
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
3
by: aurora | last post by:
This is an entry I just added to ASPN. It is a somewhat novel technique I have employed quite successfully in my code. I repost it here for more explosure and discussions. ...
2
by: Matt | last post by:
Hi, I'm ridiculously new to Access (about a week!) so please be patient! My database is a record of British Standards. Each has a unique identifier. Some are split into parts. I would like...
5
by: The Pipe | last post by:
Hello I have a table that I need to export to a .asc file format. I have had several attempts at getting this to work but with no luck. Basically the file would need to have every record...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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...

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.