Chat with a LIVE Microsoft Access Expert!
 
       
 

         

   

Go Back   Access World Forums > Microsoft Access Reference > Access FAQs

 
 
Chat with a LIVE Microsoft Access Expert!
Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 11-19-2009, 06:09 PM
ajetrumpet ajetrumpet is offline
Banned
 
Join Date: Jun 2007
Location: Universe - Local Group - Milky Way Galaxy - Orion Arm
Posts: 5,647
ajetrumpet has a spectacular aura aboutajetrumpet has a spectacular aura about
Send a message via MSN to ajetrumpet Send a message via Yahoo to ajetrumpet
Read / Write To Text Files

The attached example shows how you can get data into and out of a text file by using the File System Object and variations of the Read/Write methods.

This is probably the most common method used, as it writes in append mode, and not in write mode, and it also reads an entire file instead of only the first line...


3/6/2010
I will post some streaming examples once in a while here. Most of it will be code that I use or have used.

Code to create a (comma) delimited text file spreadsheet of all files in a windows folder:
PHP Code:
    Dim fsff1fcsoFilefolderspec
    folderspec 
"FOLDER ADDRESS"
    
Set fs CreateObject("Scripting.FileSystemObject")
    
Set f fs.GetFolder(folderspec)
    
Set fc f.Files
    
For Each f1 In fc

Left(f1.Name, (Len(f1.Name) - 4)) & "," Round(f1.Size 10485760) & "mb"
vbCrLf

    Next
       
   Set oFile 
fs.createtextfile("COMPLETE ADDRESS OF NEW TEXT FILE"True)

   
oFile.writeline s
   oFile
.Close
   
    Set f 
Nothing
    Set fc 
Nothing
    Set fs 
Nothing
    Set oFile 
Nothing 

I just ran into a text file that had no definite delimiter and it wasn't fixed width either (don't ask me where I got it). Interesting format:



My fix-it solution to make it importable into Access:
PHP Code:
    Dim fssoFilestrpartstrsplitretstring
    Set fs 
CreateObject("Scripting.FileSystemObject")
       
   
Set oFile fs.opentextfile("FILE'S PATH"1False)

   
oFile.read(111111111)
   
oFile.Close
   
    
For Each strpart In Split(svbCrLf)
        If 
InStr(strpart"-----") = 0 Then
            
For Each strsplit In Split(strpart"|")
                
retstring retstring Trim(strsplit) & ","
            
Next strsplit
                    retstring 
Trim_
                                Right
_
                                Replace
_
                                    retstring
",,"""), _
                                    
(Len(retstring) - 1))) & vbCrLf
                                
        End 
If
    
Next strpart
    
   Set oFile 
fs.createtextfile("FILE'S PATH"True)

   
oFile.writeline retstring
   oFile
.Close
   
    Set fs 
Nothing
    Set oFile 
Nothing 
Attached Files
File Type: zip Text File Streaming.zip (22.3 KB, 102 views)
File Type: zip Text File Streaming (2000).zip (22.2 KB, 64 views)

Last edited by ajetrumpet; 03-07-2010 at 02:23 PM..
Reply With Quote
Sponsored Links
  #2  
Old 11-23-2009, 05:55 AM
JohnLee JohnLee is offline
Registered User
 
Join Date: Mar 2007
Posts: 389
JohnLee is on a distinguished road
Re: Read / Write To Text Files

Hi ajetrumpet,

I'm looking to learn about how to write code that reads and writes to text files, I came across your thread and downloaded your zip file, unfortunately I am using a lower version and therefore have been unable to view the contents of your database.

I thought I'd ask, would it be possible for you to provided a way of accessing the information in your database so that I can learn how to read and write to text files.

I'm using Access 2000.

your assistance would be appreciated.

John Lee
Reply With Quote
  #3  
Old 11-23-2009, 06:23 AM
ajetrumpet ajetrumpet is offline
Banned
 
Join Date: Jun 2007
Location: Universe - Local Group - Milky Way Galaxy - Orion Arm
Posts: 5,647
ajetrumpet has a spectacular aura aboutajetrumpet has a spectacular aura about
Send a message via MSN to ajetrumpet Send a message via Yahoo to ajetrumpet
Re: Read / Write To Text Files

John,

I posted a 2000 version. Good luck.
Reply With Quote
Sponsored Links
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read first word from a text box Ashfaque General 19 01-29-2008 11:16 AM
Need Subforms & Other Columns in Tables? AccessRookie Forms 0 03-28-2005 11:42 AM
How do I issue items from a multi-level inventory? ltl Forms 5 01-27-2004 11:32 AM
Pictures and Text rmarquez5 Reports 0 01-21-2004 10:35 PM
I need to write an IF statement that dos a conditional search of a text string temo Modules & VBA 4 10-03-2003 10:22 AM


All times are GMT -8. The time now is 10:42 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
(c) copyright 2009 Access World