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

importing data

Hi Folks:
I'm trying to do something that looks simple, but I can't make it
work right.

It's Access 2000 on a Win2000 computer. I create a database with 5
columbs. The data I need to import is text. The way it's formatted
is one line each field, for the 5 fields, then to the next record.
The text file looks like this:

WPTJ410
MG
Active
7/1/2011
10/15/2001 7:54:17 AM
KKC325
IG
Active
4/20/2013
3/1/2003 12:49:12 AM
WPNE621
MG
Active
5/12/2012 1:32:31 PM
4/9/2002 12:51:12 AM
....etc..

This is the first 3 records, 5 fields each. What I'm trying to make
it look like is something like this:
__________________________________________________ ___________________
WPTJ410 | MG | Active | 7/1/2011 | 10/15/2001 7:54:17 AM
KKC325 | IG | Active | 4/20/2013 | 3/1/2003 12:49:12 AM
WPNE621 | MG | Active | 5/12/2012 1:32:31 PM | 4/9/2002 12:51:12 AM

Something like that. I can enter the data by hand, just as it is in
the text file with the returns, and it works fine! Importing always
puts the data down the first columb. So does Copy/Paste. I use to do
this all the time with Microsoft Works..

Any help appreciated. I MUST be missing something. This should be
easy.
Thanks!
Harry
Nov 13 '05 #1
8 2507
My first idea is this

Import your data in Excel
Add Column before A to add RowRanking 1 >
Put data in rows: C1=B1 D1=B2 E1=B3 F1=B4 G1=B5 and copy this till the
end of data in columnB
Rows 1, 6, 11 etc has the correct data in rows colmunsC > G
Import Excelsheet in Access
Import the correct rows in your table. Select row 1, 6, 11 . I use a
function in a query

SELECT Sheet1.F3, Sheet1.F4, Sheet1.F5, Sheet1.F6, Sheet1.F7
FROM Sheet1
WHERE (((VijfVoud([Sheet1]![F1]-1))=True));
Public Function VijfVoud(ByVal iGetal As Variant) As Boolean
VijfVoud = False
If iGetal = 0 Then VijfVoud = True: Exit Function
If iGetal Mod 5 = 0 Then VijfVoud = True
End Function

Filip

"harry" <ha********@hotmail.com> wrote in message
news:10*************************@posting.google.co m...
Hi Folks:
I'm trying to do something that looks simple, but I can't make it
work right.

It's Access 2000 on a Win2000 computer. I create a database with 5
columbs. The data I need to import is text. The way it's formatted
is one line each field, for the 5 fields, then to the next record.
The text file looks like this:

WPTJ410
MG
Active
7/1/2011
10/15/2001 7:54:17 AM
KKC325
IG
Active
4/20/2013
3/1/2003 12:49:12 AM
WPNE621
MG
Active
5/12/2012 1:32:31 PM
4/9/2002 12:51:12 AM
...etc..

This is the first 3 records, 5 fields each. What I'm trying to make
it look like is something like this:
__________________________________________________ ___________________
WPTJ410 | MG | Active | 7/1/2011 | 10/15/2001 7:54:17 AM
KKC325 | IG | Active | 4/20/2013 | 3/1/2003 12:49:12 AM
WPNE621 | MG | Active | 5/12/2012 1:32:31 PM | 4/9/2002 12:51:12 AM

Something like that. I can enter the data by hand, just as it is in
the text file with the returns, and it works fine! Importing always
puts the data down the first columb. So does Copy/Paste. I use to do
this all the time with Microsoft Works..

Any help appreciated. I MUST be missing something. This should be
easy.
Thanks!
Harry

Nov 13 '05 #2
My second idea is this !

This Excel-macro does all the work for you:
Macro expects: data in ColumnA and 5 fields per record, always 5 !!

1. Import your data in Excel
2. Add the marco below
3. Run the marco ( Change the code if FieldCount<>5)
4. Import Excelsheet in Access

***************************************
Sub Columns2Rows()
'
' CopyColumns2Rows Macro
' Macro recorded 30/10/2003 by Filips Benoit
'Declarations
Dim iLastRowNr As Integer
Dim iLoop As Integer
Dim iLoop2 As Integer
Dim iRecordFields As Integer
iRecordFields = 5 'Change for other FieldCount
'1 Block Screenupdating
Application.ScreenUpdating = False
Application.Cursor = xlWait
'2 Find last datarow in column A
Columns("A:A").Select
iLastRowNr = Selection.Cells.Find(What:="*", After:=[A1],
SearchDirection:=xlPrevious).Row
'3 Find and store RecordStartRowNrs
For iLoop = 1 To iLastRowNr Step iRecordFields
For iLoop2 = 1 To iRecordFields
ActiveSheet.Cells(iLoop, iLoop2 + 1).Value =
ActiveSheet.Cells(iLoop + iLoop2 - 1, 1).Value
Next iLoop2
Next
'4 Delete old data
Columns("B:F").Select
Selection.Sort Key1:=Range("B1"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft

'5 Update screen
Application.ScreenUpdating = True
Application.Cursor = xlDefault

End Sub
****************************************

"Filips Benoit" <be***********@pandora.be> wrote in message
news:ju***********************@phobos.telenet-ops.be...
My first idea is this

Import your data in Excel
Add Column before A to add RowRanking 1 >
Put data in rows: C1=B1 D1=B2 E1=B3 F1=B4 G1=B5 and copy this till the end of data in columnB
Rows 1, 6, 11 etc has the correct data in rows colmunsC > G
Import Excelsheet in Access
Import the correct rows in your table. Select row 1, 6, 11 . I use a
function in a query

SELECT Sheet1.F3, Sheet1.F4, Sheet1.F5, Sheet1.F6, Sheet1.F7
FROM Sheet1
WHERE (((VijfVoud([Sheet1]![F1]-1))=True));
Public Function VijfVoud(ByVal iGetal As Variant) As Boolean
VijfVoud = False
If iGetal = 0 Then VijfVoud = True: Exit Function
If iGetal Mod 5 = 0 Then VijfVoud = True
End Function

Filip

"harry" <ha********@hotmail.com> wrote in message
news:10*************************@posting.google.co m...
Hi Folks:
I'm trying to do something that looks simple, but I can't make it
work right.

It's Access 2000 on a Win2000 computer. I create a database with 5
columbs. The data I need to import is text. The way it's formatted
is one line each field, for the 5 fields, then to the next record.
The text file looks like this:

WPTJ410
MG
Active
7/1/2011
10/15/2001 7:54:17 AM
KKC325
IG
Active
4/20/2013
3/1/2003 12:49:12 AM
WPNE621
MG
Active
5/12/2012 1:32:31 PM
4/9/2002 12:51:12 AM
...etc..

This is the first 3 records, 5 fields each. What I'm trying to make
it look like is something like this:
__________________________________________________ ___________________
WPTJ410 | MG | Active | 7/1/2011 | 10/15/2001 7:54:17 AM
KKC325 | IG | Active | 4/20/2013 | 3/1/2003 12:49:12 AM
WPNE621 | MG | Active | 5/12/2012 1:32:31 PM | 4/9/2002 12:51:12 AM

Something like that. I can enter the data by hand, just as it is in
the text file with the returns, and it works fine! Importing always
puts the data down the first columb. So does Copy/Paste. I use to do
this all the time with Microsoft Works..

Any help appreciated. I MUST be missing something. This should be
easy.
Thanks!
Harry


Nov 13 '05 #3
"Filips Benoit" <be***********@pandora.be> wrote in message news:<aJ**********************@phobos.telenet-ops.be>...
My second idea is this !

This Excel-macro does all the work for you:
Macro expects: data in ColumnA and 5 fields per record, always 5 !!

1. Import your data in Excel
2. Add the marco below
3. Run the marco ( Change the code if FieldCount<>5)
4. Import Excelsheet in Access


Certainly it couldn't be that complicated! I was thinking of creating
an array of 5 elements, filling the array by looping through 5 fields
at a time (a single record), and writing the record to the database.
No Excel required.
Nov 13 '05 #4
I guess I'm missing something too, because it took me forever to get
this to work. And it still needs work - like error trapping and
adding in the OpenFile API from Ken Getz... But this part worked for
me. (Note: yes, the code is awful, but I hear James Fortune just
dying to tear it apart and correct it for ya.)

It really needs that API implemented and then it would be much more
useable - just pass the filename to the subroutine and have at it.

'--BEGIN CRUMMY CODE----
Option Compare Database
Option Explicit

Public Sub ImportWeirdFile()
'reads the first record twice and then starts skipping....

Dim varData(0 To 4) As Variant
Dim intFileNo As Integer
Dim intCounter As Integer
Dim strFileName As String

'use KG's OpenFile API to get the file you want to import...
strFileName = "C:\Documents and Settings\Pieter
Linden\Desktop\ImportMe.txt"

intFileNo = FreeFile
intCounter = 0

Open strFileName For Input As #intFileNo
Do While Not EOF(intFileNo) ' Loop until
end of file.

Line Input #1, varData(intCounter) ' Read line
into variable.
Debug.Print intCounter, varData(intCounter) ' output the
line to the screen

If intCounter = 4 Then 'then the
"record" is full, so write to table.
Call WriteValuesToTable(varData)
'Debug.Print
'Debug.Print "end of record"
'Debug.Print

intCounter = 0 'reset the counter
Else
intCounter = intCounter + 1
End If
Loop
Close #intFileNo
End Sub

Public Sub WriteValuesToTable(varMyData As Variant)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim intCounter As Integer

Set db = CurrentDb
Set rs = db.OpenRecordset("tblImportStuff", dbOpenTable,
dbappendonly)
Debug.Print "Call from WriteValuesToTable"

rs.AddNew
For intCounter = 0 To 4
rs.Fields(intCounter) = varMyData(intCounter)
Debug.Print intCounter, varMyData(intCounter)
Next intCounter
'Debug.Print
rs.Update

Set rs = Nothing
Set db = Nothing
End Sub

'--END CRUMMY CODE, BEGIN Snickering...

Pieter
Nov 13 '05 #5
pi********@hotmail.com (Pieter Linden) wrote in message news:<bf**************************@posting.google. com>...
I guess I'm missing something too, because it took me forever to get
this to work. And it still needs work - like error trapping and
adding in the OpenFile API from Ken Getz... But this part worked for
me. (Note: yes, the code is awful, but I hear James Fortune just
dying to tear it apart and correct it for ya.)


I resemble that remark :-). I'm sorry about what happened before. I
didn't mean to cause you to lose faith in your programming mojo.

James A. Fortune
Nov 13 '05 #6
Pieter,

I had the Excel-macro on hand !
AND, most people knows how to insert and run a macro in Excel !

Filip

"Pieter Linden" <pi********@hotmail.com> wrote in message
news:bf**************************@posting.google.c om...
"Filips Benoit" <be***********@pandora.be> wrote in message

news:<aJ**********************@phobos.telenet-ops.be>...
My second idea is this !

This Excel-macro does all the work for you:
Macro expects: data in ColumnA and 5 fields per record, always 5 !!

1. Import your data in Excel
2. Add the marco below
3. Run the marco ( Change the code if FieldCount<>5)
4. Import Excelsheet in Access


Certainly it couldn't be that complicated! I was thinking of creating
an array of 5 elements, filling the array by looping through 5 fields
at a time (a single record), and writing the record to the database.
No Excel required.

Nov 13 '05 #7
ha********@hotmail.com (harry) wrote in message news:<10*************************@posting.google.c om>...
Hi Folks:
I'm trying to do something that looks simple, but I can't make it
work right.

It's Access 2000 on a Win2000 computer. I create a database with 5
columbs. The data I need to import is text. The way it's formatted
is one line each field, for the 5 fields, then to the next record.
The text file looks like this:

WPTJ410
MG
Active
7/1/2011
10/15/2001 7:54:17 AM
KKC325
IG
Active
4/20/2013
3/1/2003 12:49:12 AM
WPNE621
MG
Active
5/12/2012 1:32:31 PM
4/9/2002 12:51:12 AM
...etc..

This is the first 3 records, 5 fields each. What I'm trying to make
it look like is something like this:
__________________________________________________ ___________________
WPTJ410 | MG | Active | 7/1/2011 | 10/15/2001 7:54:17 AM
KKC325 | IG | Active | 4/20/2013 | 3/1/2003 12:49:12 AM
WPNE621 | MG | Active | 5/12/2012 1:32:31 PM | 4/9/2002 12:51:12 AM

Something like that. I can enter the data by hand, just as it is in
the text file with the returns, and it works fine! Importing always
puts the data down the first columb. So does Copy/Paste. I use to do
this all the time with Microsoft Works..

Any help appreciated. I MUST be missing something. This should be
easy.
Thanks!
Harry


If you feel like taking a walk on the wild side:

'------------------begin weird.awk----------------
BEGIN {
# first create the line for the field names.
print "\"Field1\"" "," "\"Field2\"" "," "\"Field3\"" ","
"\"Field4\"" "," "\"Field5\"";
}

function deletefirstchar(astr)
{
# delete the first character of the string if the string has any
length
if (length(astr) == 0) {return astr}
astr = substr(astr,2)
return astr
}

function deletelastchar(astr)
{
# delete the last character of the string if the string has any length
if (length(astr) == 0) {return astr}
astr = substr(astr,1,length(astr) - 1)
return astr
}

function trim(myStr)
{
lenStr = length(myStr);
if (lenStr == 0)
{return myStr}
else
{
# Cull initial blanks and tabs
while (substr(myStr,1,1)==" " || substr(myStr,1,1)=="\t") {myStr =
deletefirstchar(myStr)}
if (lenStr==0) {return myStr}
# Cull final blanks
while (substr(myStr,length(myStr),1)==" ") {myStr =
deletelastchar(myStr)}
}
return myStr;
}

{
if (length($0) > 0)
{
{printf "%s" "\"" trim($0) "\""}
if (NR / 5.0 == int(NR / 5))
{printf "\n"}
else {printf "%s" ","}
}
}
END {}
'------------------end weird.awk----------------

data1.txt
WPTJ410
MG
Active
7/1/2011
10/15/2001 7:54:17 AM
KKC325
IG
Active
4/20/2013
3/1/2003 12:49:12 AM
WPNE621
MG
Active
5/12/2012 1:32:31 PM
4/9/2002 12:51:12 AM

Command line: C:\Gawk> gawk -f weird.awk data1.txt > out.csv

out.csv
"Field1","Field2","Field3","Field4","Field5"
"WPTJ410","MG","Active","7/1/2011","10/15/2001 7:54:17 AM"
"KKC325","IG","Active","4/20/2013","3/1/2003 12:49:12 AM"
"WPNE621","MG","Active","5/12/2012 1:32:31 PM","4/9/2002 12:51:12 AM"

out.csv can be imported into Access as a comma delimited file and
making sure that the box is checked for field names on the first line.
If the data has any commas in it, it would be better to create a tab
delimited format. Dates can be imported as strings and changed to
Date/Time format in Access. Note that without trim() and its helper
functions this script would be about 16 lines long. Also note that
all the relevant files must be in C:\Gawk for the command line to work
as shown (gawk.exe, weird.awk and data1.txt).

James A. Fortune
Nov 13 '05 #8
Here, got my mojo working a bit better... Note: you have to get Ken
Getz's OpenFile API from here:

http://www.mvps.org/access/api/api0001.htm

'---code could really use some error trapping....

Option Compare Database
Option Explicit

'this is on a form... the API stuff is in a public module.

Public Sub ImportWeirdFile()

Dim varData(0 To 4) As Variant
Dim intFileNo As Integer
Dim intCounter As Integer
'These are for KG's OpenFile API call
Dim strFilter As String
Dim strInputFileName As String

'--This line is calling the public stuff from the API module...
strFilter = ahtAddFilterItem(strFilter, "Text Files (*.TXT)",
"*.TXT")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)
intFileNo = FreeFile
intCounter = 0

Open strInputFileName For Input As #intFileNo
Do While Not EOF(intFileNo) ' Loop until
end of file.

Line Input #1, varData(intCounter) ' Read line
into variable.
Debug.Print intCounter, varData(intCounter) ' output the
line to the screen

If intCounter = 4 Then 'then the
"record" is full, so write to table.
Call WriteValuesToTable(varData) '--separate
only to help debug this mess!
'Debug.Print
'Debug.Print "end of record"
'Debug.Print

intCounter = 0 'reset the counter
Else
intCounter = intCounter + 1
End If
Loop
Close #intFileNo
End Sub

Public Sub WriteValuesToTable(varMyData As Variant)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim intCounter As Integer

Set db = CurrentDb
Set rs = db.OpenRecordset("tblImportStuff", dbOpenTable,
dbappendonly)

rs.AddNew
'--copy the data from the array into the table.
'--I used a zero-based array because the fields collection is
zero-based too...
For intCounter = 0 To 4
rs.Fields(intCounter) = varMyData(intCounter)
Next intCounter

rs.Update
rs.Close

Set rs = Nothing
Set db = Nothing
End Sub
Nov 13 '05 #9

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

Similar topics

2
by: steve | last post by:
Hi, I have researched but have not found a good solution to this problem. I am importing large amounts of data (over 50 Meg) into a new mysql db that I set up. I use >mysql dbname <...
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...
7
by: Darren | last post by:
I have been attempting to create a reservation planning form in excel that imports Data from an Access database and inserts that information automaticly into the correct spreed sheet and the...
2
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...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
0
by: Mike Collins | last post by:
I am importing a XML file and have not been having the best of luck in doing this, but I do have the following solution below. I will not be importing more than 2000 records at a time, but will be...
2
by: Mike Collins | last post by:
I am importing a XML file and have not been having the best of luck in doing this, but I do have the following solution below. I will not be importing more than 2000 records at a time, but will be...
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...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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.