Find/Replace data in a .txt file inthe background

G

Guest

I have an Access form that will be FTPing information. The FTP code will be
using a text file located on the hard drive. This text file will have
symbolics in it that will be replaced by entries on the Access form. I am
looking for code to open the FTP text file in the background and run a
find/replace based on fields on the form.

Thanks.
 
D

Douglas J. Steele

Read the file into a variable using the VBA Open and Input statements:

Dim intFile As Integer
Dim strBuffer As String
Dim strFile As String

strFile = "C:\Folder\File.txt"
intFile = FreeFile()
Open strFile For Input As #intFile
strBuffer = Input(FileLen(strFile) - 1, #intFile)
Close #intFile

Use the Replace function to make whatever changes you want to the content,
then write it back out using the Print statement:

intFile = FreeFile()
Open strFile For Output As #intFile
Print #intFile, strBuffer
Close #intFile

(Yes, I recommend using FreeFile twice, just in case something else is
grabbing handles to files at the same time)
 
G

Guest

Thanks...that worked great. I see you are aslo a mainframer. This
application I am working on is the front end to FTP'ing JCL with an instream
Easytrieve up to the mainframe and kicks off the job and then FTP's the
report back to the server. The Replace function will now allow the user to
dynamically change the JCL to run against the different test regions with the
use of this Access front end form.
I have bookmarked your home page....so if you have any cool stuff you would
like to share about tying Access to the mainframe I will check in ever so
often.

Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top