473,471 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Importing Text File that is vertically oriented

Hi,

I have a MS access database into which I need to import a text file
that is oriented vertically (fields are listed from top to bottom with
the value for each field appearing to the right of the field name (with
a "|" as a delimiter)). The text file will only have 1 record's data.
I would ideally like to setup a linked table to import this data - does
anyone know of a way I can setup this import?

Any help that can be provided would be greatly appreciated.

Best wishes,

George Hadley
gh********@yahoo.com

Dec 31 '05 #1
3 2441
gh********@yahoo.com wrote:
Hi,

I have a MS access database into which I need to import a text file
that is oriented vertically (fields are listed from top to bottom with
the value for each field appearing to the right of the field name (with
a "|" as a delimiter)). The text file will only have 1 record's data.
I would ideally like to setup a linked table to import this data - does
anyone know of a way I can setup this import?

Any help that can be provided would be greatly appreciated.

Best wishes,

George Hadley
gh********@yahoo.com


Well, you should know what fields are associated with a line number or
some other way to identify the field. Let's say you have a table called
Table1. ID (autonumber) is the first column which would have an index
of 0, and the rest is of text file matches the first 10 fields. Some
code like the following would work

Private Sub ReadFile(strFile As String)

Close #1
Open strFile For Input As #1 'open the text file

Dim intCnt As Integer
Dim strLine As String
Dim rst As Recordset
set rst = Currentdb.Openrecordset("Table1",dbopendynaset)
rst.AddNew

Do While Not EOF(1) ' Loop until end of text file.
Line Input #1, strLine ' assign text file line to variable
intCnt = intCnt = 1 ' increment index counter
rst(intCnt) = strLine ' update with value from text file
Loop

rst.Update
rst.Close
set rst = Nothing

Close #1
End Sub

Now, strLine could contain a date, a number, or text. Depending on the
field type, you may need to use CLng, CInt, CDate, etc to convert the
value from a string to number or date when updating the field.
Dec 31 '05 #2
gh********@yahoo.com wrote in
news:11**********************@g14g2000cwa.googlegr oups.com:
Hi,

I have a MS access database into which I need to import a text
file that is oriented vertically (fields are listed from top
to bottom with the value for each field appearing to the right
of the field name (with a "|" as a delimiter)). The text file
will only have 1 record's data. I would ideally like to setup
a linked table to import this data - does anyone know of a way
I can setup this import?

Any help that can be provided would be greatly appreciated.

Best wishes,

George Hadley
gh********@yahoo.com

Create a temporary table with two fields, one for the name and
the other for the value. Then you can create your properly
structured table using each of the datanames in the table, and
either write a crosstab query to pivot the data horizontally and
use that as the source for an append query or you can write some
visual basic code that manipulates the data and sets the value
in the final table.

so (off the top of my head, and needing support code)

rsDesti.addnew
do until rsSource.EOF
rsDesti.fields(rsSource!dataname) = rsSource!DataValue
loop
rsDesti.update
If you need help with any of this, post again.

--
Bob Quintal

PA is y I've altered my email address.
Dec 31 '05 #3
On Sat, 31 Dec 2005 16:05:29 GMT, salad <oi*@vinegar.com> wrote:
gh********@yahoo.com wrote:
Hi,

I have a MS access database into which I need to import a text file
that is oriented vertically (fields are listed from top to bottom with
the value for each field appearing to the right of the field name (with
a "|" as a delimiter)). The text file will only have 1 record's data.
I would ideally like to setup a linked table to import this data - does
anyone know of a way I can setup this import?

Any help that can be provided would be greatly appreciated.

Best wishes,

George Hadley
gh********@yahoo.com

Well, you should know what fields are associated with a line number or
some other way to identify the field. Let's say you have a table called
Table1. ID (autonumber) is the first column which would have an index
of 0, and the rest is of text file matches the first 10 fields. Some
code like the following would work

Private Sub ReadFile(strFile As String)

Close #1
Open strFile For Input As #1 'open the text file

Dim intCnt As Integer
Dim strLine As String
Dim rst As Recordset
set rst = Currentdb.Openrecordset("Table1",dbopendynaset)
rst.AddNew

Do While Not EOF(1) ' Loop until end of text file.
Line Input #1, strLine ' assign text file line to variable
intCnt = intCnt = 1 ' increment index counter


intCnt = intCnt + 1 ' minor typo
rst(intCnt) = strLine ' update with value from text file
Loop

rst.Update
rst.Close
set rst = Nothing

Close #1
End Sub

Now, strLine could contain a date, a number, or text. Depending on the
field type, you may need to use CLng, CInt, CDate, etc to convert the
value from a string to number or date when updating the field.


Jan 1 '06 #4

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

Similar topics

11
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...
1
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...
2
by: kuhni | last post by:
Hi everybody, I am totally desperate because I cannot solve a really simple problem: I have a specific text-file which I want to import into an existing database. The problem is that the columns...
2
by: Lyn | last post by:
What is the best way to import a picture (bmp format) via VBA from a Windows file and embed it into a Bound Object Frame (and thence to an OLE Object in a table)? I found an MS knowledge base...
5
by: Howard Kaikow | last post by:
I have files to build a C project, including the makefile, what's the easiest way to import the project into C and C# in VS .NET Professional? I have both VS .NET 2002 and 2003. I have nothing...
11
by: panic attack | last post by:
Hello everbody, Our system is using Sql Server 2000 on Windows XP / Windows 2000 We have a text file needs to be imported into Sql Server 2000 as a table. But we are facing a problem which is,...
5
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...
12
by: JMO | last post by:
I can import a csv file with no problem. I can also add columns to the datagrid upon import. I want to be able to start importing at the 3rd row. This will pick up the headers necessary for the...
2
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...
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
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,...
0
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...
0
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.