473,789 Members | 2,785 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

text file reading in Access using VBA

Hi everyone,

I have a question about text file reading with VBA. I want to read he
whole contents of the file in one string variable.

I have been able to successfully read lines using:

Line Input #inputFile, inputLine ' read line into inputLine string

But is there any input command that lets me read the whole file into a
string variable without worrying about delimiters and all that.

Thanks a lot for any help you might give me,

Anja

Oct 14 '06 #1
5 32467
"Anja" <an*******@goog lemail.comwrote in news:1160842037 .079468.300920
@b28g2000cwb.go oglegroups.com:
Hi everyone,

I have a question about text file reading with VBA. I want to read he
whole contents of the file in one string variable.

I have been able to successfully read lines using:

Line Input #inputFile, inputLine ' read line into inputLine string

But is there any input command that lets me read the whole file into a
string variable without worrying about delimiters and all that.

Thanks a lot for any help you might give me,

Anja
Air Code Function

Public Function ReadFile$(byval fileName$)
Dim fileNumber%
fileNumber = FreeFile()
Open fileName For Binary As #fileNumber
ReadFile = String(LOF(file Number), vbNullChar)
Get #fileNumber, , ReadFile
Close #fileNumber
End Function

--
Lyle Fairfield
Oct 14 '06 #2

Lyle Fairfield wrote:
"Anja" <an*******@goog lemail.comwrote in news:1160842037 .079468.300920
@b28g2000cwb.go oglegroups.com:
Hi everyone,

I have a question about text file reading with VBA. I want to read he
whole contents of the file in one string variable.

I have been able to successfully read lines using:

Line Input #inputFile, inputLine ' read line into inputLine string

But is there any input command that lets me read the whole file into a
string variable without worrying about delimiters and all that.

Thanks a lot for any help you might give me,

Anja

Air Code Function

Public Function ReadFile$(byval fileName$)
Dim fileNumber%
fileNumber = FreeFile()
Open fileName For Binary As #fileNumber
ReadFile = String(LOF(file Number), vbNullChar)
Get #fileNumber, , ReadFile
Close #fileNumber
End Function

--
Lyle Fairfield
Hi there,

Thanks for replying.

The line:

Get #fileNumber, , ReadFile

returns an error "Variable uses an automation type not supported in
Visual Basic".

I am using VBA under Access.

Thanks,
Anja

Oct 14 '06 #3
"Anja" <an*******@goog lemail.comwrote in
news:11******** **************@ f16g2000cwb.goo glegroups.com:
>
Lyle Fairfield wrote:
>"Anja" <an*******@goog lemail.comwrote in
news:116084203 7.079468.300920 @b28g2000cwb.go oglegroups.com:
Hi everyone,

I have a question about text file reading with VBA. I want to read
he whole contents of the file in one string variable.

I have been able to successfully read lines using:

Line Input #inputFile, inputLine ' read line into inputLine string

But is there any input command that lets me read the whole file
into a string variable without worrying about delimiters and all
that.

Thanks a lot for any help you might give me,

Anja

Air Code Function

Public Function ReadFile$(byval fileName$)
Dim fileNumber%
fileNumber = FreeFile()
Open fileName For Binary As #fileNumber
ReadFile = String(LOF(file Number), vbNullChar)
Get #fileNumber, , ReadFile
Close #fileNumber
End Function

--
Lyle Fairfield

Hi there,

Thanks for replying.

The line:

Get #fileNumber, , ReadFile

returns an error "Variable uses an automation type not supported in
Visual Basic".

I am using VBA under Access.
Me too. This works here in Canada:

Debug.Print ReadFile("C:\Do cuments and Settings\Lyle Fairfield\My
Documents\Geoca cheTextFiles\(G CNHHP) MULTI-AGREEMENT CONLEY TRACT by
BigLittleZee.tx t")

(that's all one line)
--
Lyle Fairfield
Oct 14 '06 #4
Hmm, posted this just the other day.

Sub ImportData(File Name As String)
Dim intFF As Integer
Dim strLine As String
Dim varLines As Variant
Dim intLine As Integer

intFF = FreeFile

Open FileName For Binary Access Read Lock Read Write As intFF

strLine = Space(LOF(intFF ))
Get intFF, , strLine
Close intFF

varLines = Split(strLine, vbCrLf)

' Now you can step through the varLines array
' and put the relevant data into the correct
' fields in your table.

End Sub
--

Terry Kreft
"Anja" <an*******@goog lemail.comwrote in message
news:11******** **************@ b28g2000cwb.goo glegroups.com.. .
Hi everyone,

I have a question about text file reading with VBA. I want to read he
whole contents of the file in one string variable.

I have been able to successfully read lines using:

Line Input #inputFile, inputLine ' read line into inputLine string

But is there any input command that lets me read the whole file into a
string variable without worrying about delimiters and all that.

Thanks a lot for any help you might give me,

Anja

Oct 15 '06 #5
"Anja" <an*******@goog lemail.comwrote in
news:11******** **************@ b28g2000cwb.goo glegroups.com:
Hi everyone,

I have a question about text file reading with VBA. I want to read he
whole contents of the file in one string variable.

I have been able to successfully read lines using:

Line Input #inputFile, inputLine ' read line into inputLine string

But is there any input command that lets me read the whole file into a
string variable without worrying about delimiters and all that.

Thanks a lot for any help you might give me,

Anja
I tested Lyle's function on Win98/Office 8 with no problems.

Sub Test()
MsgBox (Len(ReadFile(" C:\WINDOWS\Appl ication Data\AVG7\Log\e mc.log")))
End Sub

This worked too.

Function FileToOneString ()
Dim MyReadNum As Integer
Dim theGuts As Variant
'--
Rem FileToOneString (FileIN$)
Dim FileIN$
FileIN$ = "C:\WINDOWS\App lication Data\AVG7\Log\e mc.log"
'--
MyReadNum = FreeFile
Open FileIN For Input As MyReadNum

theGuts = Input$(LOF(MyRe adNum), MyReadNum)
Close MyReadNum

MsgBox "Length is " & Len(theGuts) & vbCrLf & Right(theGuts, 40)
FileToOneString = theGuts
End Function

My test file was about nine Megs. I'm not sure what the limit is.

Cheers,
Alan
Oct 16 '06 #6

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

Similar topics

16
12641
by: Michael | last post by:
I have a data application in a2k that I need to create two fixed width text files and then combine them to a single file The first file is header information and the second is transaction data. I have tried and tried but just cant seem to get this right, I am using Queries to created my export files with specifications which works fine, I get stumped with the appending the header to my transaction file. What I have so far looks like...
5
11597
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 correct once the data is in Access (or during the import process itself). Furthermore, the text files are poorly set up, such that some records may be "shifted" over a few characters, and therefore the fixed width nature of the file is corrupted. ...
6
23776
by: G.Esmeijer | last post by:
Friends, I would like to read a text file (fixed length formaated) really fast and store the data into an Access database (2003). Using the streamreader and reading line by line, separating the line into string just takes to long. When I Import the file with access manually goes fast. But how to use this fromout a C# programme who has done this before and who can give met some answers
1
1494
by: Yama | last post by:
Hi Is there a way using an Intranet ASP.NET web application to access a text file from a specified folder The Logic ReadTextFile.asp ------------------- FILE = "a_comma_delimited_text_file.txt PATH = "C:\folder\subfolder\
5
1622
by: Eric A. Johnson | last post by:
I'm trying to create a text file, write to it, close it, then reopen the same file for reading (line by line). I've so far been able to successfully open the file, write to it, then close it. I let the user decide which file to write to, using the following code: ' File writing/reading variables Dim SaveFileResult As SaveFileDialog Dim TextFileStream As FileStream
2
3233
by: Wes Peters | last post by:
Does anyone know of an article that deals with the subject of reading a structured text file using VBA code in Access? Thanks, Wes
1
2326
by: Roy | last post by:
Hi, Thanks for helping.I have an A2K Appl.Recently,one of the groups agreed to provide data which I download into the access table.The problem is this data which is sent in a text file.I am unable to import it because of the delimiter tab.The tab is present in places where it is unable to identify one problem ID from the second one.I need help.I am pasting a sample taxt file here. ...
14
11265
by: mfrsousa | last post by:
hi there, i have a huge large text file (350.000 lines) that i want to import to a MS Acccess Database, of course i don't want to use Access, but do it with C#. i already have tried the AddRow method or Insert, reading each line of the text file, the problem of course is velocity, it would take more than 4 hours to add all lines/records to the database.
6
249000
Atran
by: Atran | last post by:
Hello: In this article: You will learn to Write or Read A Text File. Let's Begin: First Create a new project (ConsoleApp or WinApp). And Make sure your program uses these namespaces: using System; using System.IO; using System.Diagnostics;
5
11280
by: dm3281 | last post by:
Hello, I have a text report from a mainframe that I need to parse. The report has about a 2580 byte header that contains binary information (garbage for the most part); although there are a couple areas that have ASCII text that I need to extract. At the end of the 2580 bytes, I can read the report like a standard text file. It should have CR/LF at the end of each line. What is the best way for me to read this report using C#. It is...
0
9511
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,...
0
10408
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10199
jinu1996
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...
0
9983
tracyyun
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...
0
9020
agi2029
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...
1
7529
isladogs
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...
0
5417
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2909
bsmnconsultancy
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...

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.