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

Import Text - Problem With Limits

Okay, I checked with usual suspects and I'm still frustrated.

..txt file, fixed width. About 88 fields of varying length. All text
fields. It will only let me add seperators to about the 410th position but
there are 420 positions.

What's going on?
Nov 13 '05 #1
1 2369
This problem is not uncommon. Wizards are quite useful but can only be
so generic. The workaround for this limitation is to develop a routine
which is a little bit less generic for your purposes (vb.Net is
notorious for limited wizardry - but a great platform!).

I am sharing a somewhat generic VBA code routine which uses DAO code
which you can copy and pasted into an Access Standard Code Module or a
Form class module in a command button. What this routine does is to
bulk read data from a text file, line by line, into a table called
"Table1". Table1 contains only 1 field (you can name the field anything
you want) which is a Memo data type (memo so that if the line is several
thousand chars in length the field will still accept all of the text
from the line). Then, of course, you have to parse the data. In my
example I am reading data from a comma delimited text file. Table2 will
contain the parsed data from table1. You need to know how many columns
are in your text file in advance for this routine (I could make it more
custom, but it is just an example). Then you create Table2 with the
same number of columns. Dont worry about the datatypes. Just make
everything Text datatype, and allow for zero length string and
everything is "Not Required". Here is the routine:

Sub GetDataFromTextFile()
Dim DB As Database, RS1 As Recordset, RS2 As Recordset
Dim strPath As String, str1 As String, str2 As String
Dim i As Integer, j As Integer, k As Integer
Dim bContinue As Boolean
'empty out Tables1 and 2 incase you reuse this routine
DoCmd.RunSQL "Delete Rows From Table1"
DoCmd.RunSQL "Delete Rows From Table2"
Set DB = CurrentDb
Set RS1 = DB.OpenRecordset("Table1")
strPath = Left(DB.Name, Len(DB.Name) - Len(Dir(DB.Name)))
Open strPath & "\TestFile.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, str1
RS1.AddNew
RS1(0) = str1
RS1.Update
Loop
Close #1
RS1.MoveFirst 'move record point to beginning of Table1

Set RS2 = DB.OpenRecordset("Table2")
Do While Not RS1.EOF
j = 1 'j demarks the place after each delimiter
k = 0 'k is the field counter for Table2
bContinue = True 'continue while the line contains
str1 = RS1(0) 'a delimiter, str1 will contain the
RS2.AddNew 'line from Table1
Do While bContinue 'here you iterate through str1 and
i = InStr(j, str1, ",") 'use Instr Function to demark
If i = 0 Then 'comma delimeter position
bContinue = False 'if i=0 that means end of delimiter
str2 = Mid(str1, j, Len(str1) - j) 'use Mid function
Else 'to retrieve contents between delimeters
str2 = Mid(str1, j, i - j)
End If
Debug.Print str2
RS2(k) = str2
j = i + 1
k = k + 1
Loop
RS2.Update
RS1.MoveNext
Loop
RS1.Close
RS2.Close
End Sub

To test this out, create a table, tableX, with say 5 fields. Add some
fake test data, test1, test2, ... Export this to a text file called
"TestFile.txt". So now you know that you have 5 fields. Create Table1
with one field, memo datatype, Table2 with 5 field, all text datatype,
zero length allowed, everything not required. Oh, this routine also
assumes that the text file reside in the same directory as your mdb
(strPath & "\TestFile.txt"). Note: if your text file is Tab delimited,
replace "," with vbTab in the InStr function

i = InStr(j, str1, vbTab)

Good luck.

Rich

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #2

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

Similar topics

1
by: Andrew James | last post by:
All, I'm having some trouble with understanding python's importing behaviour in my application. I'm using psyco to optimise part of my code, but I'm not sure whether it inherits throughout the...
1
by: DCM Fan | last post by:
Access 2K, SP3 on Windows 2K, SP4 All, I have an import spec set up with quoted Identifiers and comma-separated values. The text file is produced by a 3rd-party program of which I have no...
1
by: mark | last post by:
In Access 2000 and 2002, I have created an import specification to import the fixed-width recordset below into an existing table. I am having strange problems with the import of the date and time...
1
by: Dan | last post by:
Could someone please help me with auto importing a series of data files into an Access table. I tried to follow code given below in a previous messagebut i'm getting error messages. Here's my...
5
by: Johnny Meredith | last post by:
I have seven huge fixed width text file that I need to import to Access. They contain headers, subtotals, etc. that are not needed. There is also some corrupt data that we know about and can...
20
by: Steve Jorgensen | last post by:
Hi all, I've just finished almost all of what has turned out to be a real bear of a project. It has to import data from a monthly spreadsheet export from another program, and convert that into...
3
by: deko | last post by:
I've been trying to use the Access Import Wizard to expedite importing data into my mdb. The nice thing about the wizard is that I can import from different file formats - txt, xls, even Outlook -...
4
by: Alec MacLean | last post by:
Is anyone aware of a size limit imposed on the subject text when using the System.Net.Mail library? I'm getting problems of message not being recieved if the subject exceeds 15 chars. Thx
13
by: Josip | last post by:
I'm trying to limit a value stored by object (either int or float): class Limited(object): def __init__(self, value, min, max): self.min, self.max = min, max self.n = value def...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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...
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,...

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.