Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text files 1

Status
Not open for further replies.

Mats

Technical User
Feb 18, 2000
83
EU
Does anybody have code for directly writing and reading text-files from Access? What I would want to do is write txt-files line by line or read a specific line from a text-file. I know how to import/export files in access, but I'm looking for a simpler way of e.g. doing a find and replace in a textfile without running it through access.

Thanks,
Mats
 
The following routine will open a file and replace every instance of 'BadString' that it finds with 'GoodString'.

Code:
Public Sub Opener()
Dim FFile As Integer
Dim FileString As String

    FFile = FreeFile
    Open "C:\YourTextFile.txt" For Input As #FFile
    
    FileString = Input(LOF(FFile), #FFile)
    
    Close #FFile
    
    FileString = Replace(FileString, "BadString", "GoodString")
    
    Open "C:\YourTextFile.txt" For Output As #FFile
    Print #FFile, FileString
    
    Close #FFile
    
End Sub

if you want to go through a file one line at a time use the
Code:
 Line Input
statement. Durkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top