473,699 Members | 2,804 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5194
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.Worksp aces(0).Databas es(0)
Set rsDest = db.OpenRecordse t("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(intInputFil e)
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$(st rLineIn, Len(strLineIn) -
intFindDelim))

'--write the field to the record
rsDest.Fields(i ntCounter) = 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
3054
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 single file, but then be able to take this one single file and recreate the files I put into it. Im really at a loss as to how I go about recovering the files?
5
2512
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 code snipit** Dim strCustFullName as string Dim strCustAddr1 as string
1
1819
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 9pt font to compose this post and copied/pasted to my newsreader program. I am writing in the hope that one of you Visual Basic experts may provide a solution, or at least some insight, to the problem described below. I am not a programmer, but...
12
20921
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 contains the paths to the pictures. The database consists of two tables: TABLE DATA ID Name LastName
15
4764
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 button will verify the information that has been entered and updates the data base if the data is correct. Update will throw an exception if the data is not validate based on some given rules. I also have a custom error handling page to show the...
6
4991
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 for long running reports. When the processing is complete it uses crystal reports to load a template file, populate it, and then export it to a PDF. It works fine so far....
3
2163
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. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/475158 wy ------------------------------------------------------------------------
2
2872
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 the user to be able to input the data into a single textbox using a form like this: Record1: BS 1490-1 Record2: BS 1490-2
5
3766
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 displayed on a separate line - If you like a CrLF delimited file. The unfortunate thing is that the file is to be then imported into a third party piece of software and as such I have no other alternative but to use this file format. Does anyone have...
0
8687
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
9174
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9034
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...
0
7750
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...
1
6534
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5874
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
4376
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
4629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2009
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.