473,385 Members | 1,569 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.

Import Text Via VBA

I am trying to import a text file via VBA, I have to import via vba as
the file i am importing is not consistently formatted and I also need
to perform some manipulation of the data before it is imported. I am
building an array from a text file and then appending it via DAO.
(Example code below)
I have two problems at the moment firstly every field I import could be
empty so I am having to wrap each field in
If strarray(n) <> "" - is there an easier way of doing this?

Also I am getting a subscript out of range error when it tries to
append strarray(10) - does anyone know why this is happening?

Set RS1 = CurrentDb.OpenRecordset("tblTEMPVendors", dbOpenTable)
FP1 = FreeFile
Open Sourcefile For Input As FP1
Do Until EOF(FP1)
Line Input #FP1, strData
strArray = Split(strData, vbTab)
If Not strData = "" Then 'exclude gaps in header
If Len(strArray(0)) = 0 Then 'exclude report title in line 1
If Not strArray(1) = "Vendor" Then 'exclude column heading
RS1.AddNew
If strArray(1) <> "" Then
RS1.Fields(0).Value = strArray(1)
End If
If strArray(2) <> "" Then
RS1.Fields(1).Value = strArray(2)
End If
RS1.Update

Nov 13 '05 #1
5 6042
show us the definition of strArray()? Is it

Dim strArray(1 to 10)?

or

Dim strArray(10)?

if you used the latter, the index goes from 0 to 9, not 1 to 10.

Nov 13 '05 #2
Tom
This doesn't directly answer your questions, but have you looked at the
import text module posted at
http://www.mvps.org/access/modules/mdl0057.htm. I've used it in the
past and it has worked well.

Tom

Nov 13 '05 #3
pi********@hotmail.com wrote:
show us the definition of strArray()? Is it

Dim strArray(1 to 10)?

or

Dim strArray(10)?

if you used the latter, the index goes from 0 to 9, not 1 to 10.


Actually it will go from 0 to 10, giving 100 elements.

--
This sig left intentionally blank
Nov 13 '05 #4
Trevor Best wrote:
pi********@hotmail.com wrote:
show us the definition of strArray()? Is it

Dim strArray(1 to 10)?

or

Dim strArray(10)?

if you used the latter, the index goes from 0 to 9, not 1 to 10.


Actually it will go from 0 to 10, giving 100 elements.


Don't you mean "giving 11 elements"? Single dimension array, right?

0 to 10: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
Nov 13 '05 #5
MGFoster wrote:
Trevor Best wrote:
pi********@hotmail.com wrote:
show us the definition of strArray()? Is it

Dim strArray(1 to 10)?

or

Dim strArray(10)?

if you used the latter, the index goes from 0 to 9, not 1 to 10.


Actually it will go from 0 to 10, giving 100 elements.


Don't you mean "giving 11 elements"? Single dimension array, right?

0 to 10: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10


Um yes, 100 was a typo, still on my first cup of tea today :-)

--
This sig left intentionally blank
Nov 13 '05 #6

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

Similar topics

1
by: Chris | last post by:
Background: I am using a MS Access 2000 front end with SQL Server 8.0 back end. I have the requirement to import all text files (regardless of filename) from a given folder on the network into a...
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...
4
by: Steve Jorgensen | last post by:
I'm restarting this thread with a different focus. The project I'm working on now id coming along and will be made to work, and it's too late to start over with a new strategy. Still, I'm not...
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: Bruce W. Roeser | last post by:
All, I'm reading a book by Charles Petzold (Programming VS.Net). Pretty good content but am confused about the difference. From the text: ...
1
by: ghadley_00 | last post by:
Hi, I have a MS access database table for which I regularly need to import fixed width text data. At present I have to to cut and paste the text data from its source to a text file, save the...
0
by: NewbieSupreme | last post by:
I'm using PHPMyAdmin on an Apache2Triad install (latest version; 5.x.x, which installs PHP5 and PHPMyAdmin 2.8 as well). In Access, I exported a table to a text file, tab-delimited, text qualifyer...
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
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
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...

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.