Hello.
I have long text file whitch is formatted like this:
nextrow4
asdf
asdf
asdf
nextrow3
bsdf
bsdf
bsdf
nextrow6
cdsf
cdsf
cdsf
So the file should look like this after importing
nextrow4 | asdf | asdf | asdf
nextrow3 | bsdf | bsdf | bsdf
nextrow6 | csdf | csdf | csdf
So nextrow+"some number" or just nextrow tells to start a new row. The
linechange is indicating column change.
I'we been trying all kinds of additional software to import the
textfile but none of them did work the way I needed.
Every help will be respected, thanks!
- Nisse 7 2142
use a loop when you read through the file...
for intCounter = 0 to 3
if intCounter=0 then
rs.AddNew
end if
strLine = LineInput....
rs.fields(intco unter)=strline
rs.update
next intCounter
Okay, got it to work. (The help files in Access seem to suck more with
every release! Pretty soon they won't even bother with one, I think!)
Here's the code... and no, AFAIK, there is no way to do it with a
macro.
Except one problem that my code does not deal with... the blank lines.
I guess you could test for null...
Option Compare Database
Option Explicit
Public Sub ImportTextfile( ByVal strFile As String)
Dim db As DAO.database
Dim rs As DAO.Recordset
Dim intFileNo As Integer
Dim strText(0 To 3) As String 'holds the lines of text
Dim intCounter As Integer
Set db = CurrentDb
Set rs = db.openrecordse t("Table1", dbOpenTable, dbappendonly)
intFileNo = FreeFile
Open strFile For Input As intFileNo
Do Until EOF(intFileNo)
'read the block of 4 values into an array
For intCounter = 0 To 3
Line Input #1, strText(intCoun ter)
Next intCounter
'write the array to a record
rs.AddNew
'--sorry, the fields collection in DAO is zero-based, so I'm
counting 0...3
For intCounter = 0 To 3
rs.Fields(intCo unter) = strText(intCoun ter)
Next intCounter
'save the record
rs.Update
Loop
rs.Close
Set rs = Nothing
End Sub
oh, you're going to have to modify this a little if you have blank
lines between each value... probably just stuff your blank line into a
variable and test it for null or zero-length... But if your extra
carriage returns were just to make it more readable, this should at
least get you started...
On 21-Jun-2005, ni**********@we binfo.fi wrote: Hello.
I have long text file whitch is formatted like this:
nextrow4
asdf
asdf
asdf
nextrow3
bsdf
bsdf
bsdf
nextrow6
cdsf
cdsf
cdsf
So the file should look like this after importing
nextrow4 | asdf | asdf | asdf nextrow3 | bsdf | bsdf | bsdf nextrow6 | csdf | csdf | csdf
So nextrow+"some number" or just nextrow tells to start a new row. The linechange is indicating column change.
I'we been trying all kinds of additional software to import the textfile but none of them did work the way I needed.
Every help will be respected, thanks!
- Nisse
You didn't specify much about the text file you are reading. From the way
you formatted the data on screen, I am going to assume that each piece of
text is followed by a carriage return and that a carriage return is on each
of the blank lines between text lines.
Dim tmpStr As String
Dim inputStr() As string ' dimension as needed to handle all entries in
your "long" text file
Dim i As Integer ' index to current row
Dim x As Integer
Open (strPath & "filename.t xt") For Input As #1
i = 0
Do While Not EOF(1)
Line Input #1, tmpStr ' Input (instead of Line Input) may work
depending on delimiters in text file
x = InStr(1, tmpStr, "nextrow", vbTextCompare)
If x > 0 Then
' input contains text "nextrow"
i = i + 1
inputStr(i) = tmpStr
Else
inputStr(i) = inputStr(i) & " " & tmpStr " add more spaces or perhaps
a Tab character to get columns right
End If
Loop
Close #1
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =--- co******@aol.co m wrote: On 21-Jun-2005, ni**********@we binfo.fi wrote:
Hello.
I have long text file whitch is formatted like this:
nextrow4
asdf
asdf
asdf
nextrow3
bsdf
bsdf
bsdf
nextrow6
cdsf
cdsf
cdsf
So the file should look like this after importing
nextrow4 | asdf | asdf | asdf nextrow3 | bsdf | bsdf | bsdf nextrow6 | csdf | csdf | csdf
So nextrow+"some number" or just nextrow tells to start a new row. The linechange is indicating column change.
I'we been trying all kinds of additional software to import the textfile but none of them did work the way I needed.
Every help will be respected, thanks!
- Nisse
You didn't specify much about the text file you are reading. From the way you formatted the data on screen, I am going to assume that each piece of text is followed by a carriage return and that a carriage return is on each of the blank lines between text lines.
Dim tmpStr As String Dim inputStr() As string ' dimension as needed to handle all entries in your "long" text file Dim i As Integer ' index to current row Dim x As Integer
Open (strPath & "filename.t xt") For Input As #1 i = 0 Do While Not EOF(1) Line Input #1, tmpStr ' Input (instead of Line Input) may work depending on delimiters in text file x = InStr(1, tmpStr, "nextrow", vbTextCompare) If x > 0 Then ' input contains text "nextrow" i = i + 1 inputStr(i) = tmpStr Else inputStr(i) = inputStr(i) & " " & tmpStr " add more spaces or perhaps a Tab character to get columns right End If Loop Close #1
Of you could grab my TextFile class from
<http://www.mvps.org/access/modules/mdl0057.htm> and tell it to ignore
blank lines.....
<Grin>
Hmm... yeah, I forgot about that, Chuck. I think I used to have it on
my computer, but that one's in storage now...
Is there any way to do the rest of it, besides reading into an array or
structure and then writing to the database? Normally, one can't say
"write four records into one"... (Hey, I'm still a relative novice...)
I like that idea... I'll have to test it out. Thanks! pi********@hotm ail.com wrote: Hmm... yeah, I forgot about that, Chuck. I think I used to have it on my computer, but that one's in storage now... Is there any way to do the rest of it, besides reading into an array or structure and then writing to the database? Normally, one can't say "write four records into one"... (Hey, I'm still a relative novice...)
Personally, I wouldn't bother with the recordset. Just build a SQL
INSERT INTO string from the data you read in and then execute it,
changing the SQL String and repeating as needed. This is actually a
great way to handle situations where you have to write to multiple
tables with bits and peices of the data from the external file.
By the way, when importing from an external file of some kind, I'll
often use the line number of the file that "trigered" the insert(s) as
a "unique identifer" for the record. When things go wrong for some
reason, you have a nice way to "trace back" the information to the
source data. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Grim Reaper |
last post by:
I am importing a .csv file into Access that has 37 fields. My problem is
that sometimes the last field only has data at the end of the column (it
looks like when you import a file into Access, for the last field, it
only checks the top few 'cells' to see if there is any data, if not, the
field is not imported).
How do I 'force' Access to import the field, regardless if there is data
in the top of the field or not? For instance, I might...
|
by: D Mat |
last post by:
Hi,
I'm trying to get MS Access 2000 to automatically import a series of
(~200) flat text, tab delimited, data files into a single Access table,
with consistent fields and rows.
The files have different, but somewhat logical naming structures
(ex.Jun01.txt, Jun02.txt, Jul01.txt, etc...).
Is there a relatively simple way to accomplish this, considering i'm new
to Access. I was especially hoping to do this without having to
manually...
|
by: sparks |
last post by:
I have never done this and wanted to ask people who have what is the
best way.
One person said import it to excel, then import it into access table.
but since this will be done a lot, I am trying to avoid this extra
step.
can access read in this file directly into a table as append data?
thank you very much for any pointers
|
by: nutthatch |
last post by:
I want to be able to import an Excel spreadsheet into Access 2K using
the macro command Transferspreadsheet.
However, the file I am importing (over which I have no control)
contains some records that are "dirty" i.e. the field contents do not
comply with the expected format (date/time) and they end up in a
seperate table of import errors. (The records in "error" are actually
empty fields.)
This is a regular event and I do not want to...
|
by: hharriel |
last post by:
Hi,
I am hoping someone can help me with an issue I am having with excel
and ms access. I have collected data (which are in individual excel
files) from 49 different school districts. All districts have used the
same excel template and populated the same 32 data fields (columns). I
created one large excel file from all 49 files which gives me a master
table of 60,000 or so records. I have tried to import this master
table into access...
| |
by: Alan |
last post by:
OK this is a weird one.
I've got an import routine going whereby name and address data is pulled
into a table from a csv file.
I'm having strange results when importing postcode/zip data into a text
field. I'm also using an import specification that specifies the post/zip
code field is text.
If the contents of that column are all alphanumeric UK postcodes e.g. LL55
|
by: denisel |
last post by:
Hi,
We will be conducting surveys through SurveyMonkey online and will be importing the answers by tab delimited or comma delimited file into access. I was wondering if there is specific way to import delimited files into Access or Is there a specific way I should design the survey online so Access can recognize the file?
Here is my table structure to give you an idea on where I'm coming from. Thank you so much in advance!!!
...
|
by: Debbiedo |
last post by:
I have a text file that I am importing into an Access table that was
generatred from data exported from a Word file. Several (about 20-30)
fields are from check boxes on the Word form. These fields have either
0 (Not checked) or 1 (Checked). Due to requirements from a third party
software application, they HAVE to be either Y(Checked) or N (Not
checked) and MUST be a text field in the Access table.
I will be importing several thousand of...
|
by: Kosmos |
last post by:
Hey guys,
I'm fairly familiar with access by now, but I've never worked with importing text into an access database. I have some fairly large text files (lets say, for example, a folder of 20 text files could be about 120 mb with each text file being 6 mb). I know that Access has some strict limitations on fields and their sizes and I've learned to stay away from using memos. The files are encoded health files and so they have a '~' to...
|
by: aconti74 |
last post by:
Hello I am new to vba programming/coding. I am writing a program that
goes through a directory of text files and imports them into the
database. The problem is eventually the database gets to big and
needs to be compacted. I know how to compact on exit but how do you
do it in a loop using vba? My old program in basic did it because it
was external to access. Any ideas?
1.import text file
2.loop - check size
|
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...
| |
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,...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
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();...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| | |